0

我一直在尝试使用 Walmart Marketplace API 对沙盒和生产进行身份验证,但到目前为止还没有成功。在所有情况下,当我对“令牌 API”( https://sandbox.walmartapis.com/v3/token )执行 ping 请求时,都会返回以下错误代码:“SYSTEM_ERROR.GMP_GATEWAY_API”。我尝试使用 JSON 和 XML 进行身份验证,但没有运气。

这是我对 JSON 的请求:

{
  url: 'https://sandbox.walmartapis.com/v3/token',
  data: { grant_type: 'client_credentials' },
  options: {
    headers: {
      Authorization: 'Basic <base64String>=',
      Accept: 'application/json',
      'Content-Type': 'application/x-www-form-urlencoded',
      'WM_SVC.NAME': 'Walmart Marketplace',
      'WM_QOS.CORRELATION_ID': '1bca34cd-478f-4022-8c13-9b88293f56b2',
      'WM_SVC.VERSION': '1.0.0'
    }
  },
  method: 'post'
}

这是我在使用 JSON 时遇到的错误:

error: [
    {
      code: 'SYSTEM_ERROR.GMP_GATEWAY_API',
      description: 'Illegal character in query at index 172: http://partner-read-srvc-app.prod2.partnerreadservice1.catdev.prod.walmart.com/partner-read-srvc-app/services/org/client/search?_s=cross_ref_key==ClientId;cross_ref_value=="8cdc9a4f-3518-4941-9b62-5bc88bac5f3c;buId==0;martId==0',
      info: 'System encountered some internal error.',
      severity: 'ERROR',
      category: 'DATA',
      causes: [],
      errorIdentifiers: {}
    }

该错误提到了索引 172,但我不确定它指的是什么。在这里查看了他们的文档后,我正在严格执行。

这是我对 XML 的请求:


{
  url: 'https://sandbox.walmartapis.com/v3/token',
  data: '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n' +
    '<grant_type>client_credentials</grant_type>',
  options: {
    headers: {
      Authorization: 'Basic <base64String>=',
      Accept: 'application/xml',
      'Content-Type': 'application/xml',   
      'WM_SVC.NAME': 'Walmart Marketplace',
      'WM_QOS.CORRELATION_ID': 'be1ff777-9c7b-4ca2-8b9c-ac31696dbf79',
    }
  },
  method: 'post'
}

但这也是失败的。

有谁知道为什么这些请求可能会失败,并可能在 JS 中提供一个通过 API 进行身份验证的请求的工作示例?

4

1 回答 1

1
var request = require('request');
var options = {
  'method': 'POST',
  'url': 'https://sandbox.walmartapis.com/v3/token',
  'headers': {
    'WM_SVC.NAME': 'Walmart Marketplace',
    'WM_QOS.CORRELATION_ID': 'test',
    'Accept': 'application/json',
    'Authorization': 'Basic afafaf...',
    'WM_SVC.VERSION': ' 1.0.0',
    'Content-Type': 'application/x-www-form-urlencoded'
  },
  form: {
    'grant_type': 'client_credentials'
  }
};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});

这对我有用。确保您正确构建了授权。格式为“基本 Base64encode(cliendId:clientSecret)”

我认为您发送 grant_type 属性的方式不正确。

于 2020-05-12T17:42:01.573 回答