【问题标题】:The Walmart Marketplace OAuth API keeps throwing SYSTEM_ERROR.GMP_GATEWAY_API error沃尔玛市场 OAuth API 不断抛出 SYSTEM_ERROR.GMP_GATEWAY_API 错误
【发布时间】:2020-05-12 14:20:13
【问题描述】:

我一直在尝试使用 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,但我不确定它指的是什么。在查看了他们的文档here 之后,我正在认真执行。

这是我对 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 进行身份验证的请求的工作示例?

【问题讨论】:

  • 是 JSON 模板的 部分之后的“=”,还是编辑错误?使用 " 作为引号,并可能使用 JSON 验证器检查示例。除此之外,乍一看还不错。我有获取令牌的代码,但在 JS 中没有。如果这不起作用,你能发布你的代码?

标签: javascript xml api rest walmart-api


【解决方案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 属性的方式不正确。

【讨论】:

  • 感谢@kushan85 的回复。所以最后,由于这是第 3 方开发,问题在于 API 凭据没有被客户端正确激活!
猜你喜欢
  • 2021-02-03
  • 2017-02-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-25
  • 1970-01-01
  • 2021-10-21
相关资源
最近更新 更多