【问题标题】:Walmart inventory update not working facing 400沃尔玛库存更新无法面对 400
【发布时间】:2018-10-11 13:43:09
【问题描述】:

我正在尝试使用 curl api 更新沃尔玛库存,但遇到 400 错误响应代码的问题。

这是我的示例代码:我关注了 walmart doc,访问了错误代码相关的 walmart 文档,发现他们要求提交工单,因此没有公开找到解决方案。

$URL = "https://marketplace.walmartapis.com/v2/inventory?sku=xxxxx";
$RequestMethod = 'PUT';
$Timestamp = round(microtime(true) * 1000); //Current system timestamp
$WalmartConsumerID = "xxxxxxxxxxxxxxxxxxxxxxx";  

$Signature = _GetWalmartAuthSignature($URL, $RequestMethod, $Timestamp); 



$headers = array();
   $headers[] = "Accept: application/xml";
   $headers[] = "Content-type: application/xml";
   $headers[] = "WM_SVC.NAME: Walmart Marketplace";
   $headers[] = "WM_QOS.CORRELATION_ID: ".mt_rand();
   $headers[] = "WM_SEC.TIMESTAMP: ".$Timestamp;
   $headers[] = "WM_SEC.AUTH_SIGNATURE: ".$Signature;
   $headers[] = "WM_CONSUMER.ID: ".$WalmartConsumerID;
   $headers[] = "WM_CONSUMER.CHANNEL.TYPE: 0f3e4dd4-0514-4346-b39d-af0e00ea";




 $data = file_get_contents('inventory.xml');
   $ch = curl_init($URL);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
   curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
   curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
   curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
   $response = curl_exec($ch);
   echo $erroe = curl_error($ch);
   echo $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);   

响应:400

这正是 walmart api doc 中解释的内容。

P.S:获取库存、获取订单和更新价格,使用相同的密钥和签名可以正常工作。 这是我的 xml 数据

 <?xml version="1.0" encoding="UTF-8"?>
 <inventory xmlns:ns2="http://walmart.com/">
    <sku>Cxxxx2</sku>
    <quantity>
    <unit>EACH</unit>
    <amount>7</amount>
    </quantity>
    <fulfillmentLagTime>1</fulfillmentLagTime>
    </inventory>

【问题讨论】:

  • 您是否仔细检查过您的$data-变量是否包含正确的字段?我们很难帮助您调试此问题,因为我们不知道您发布的数据是什么。
  • @MagnusEriksson 我用数据更新了问题。

标签: php xml curl walmart-api


【解决方案1】:

其他 API 是否正常工作?我问的原因是因为我看到在 _GetWalmartAuthSignature 的示例代码中,您没有传递生成签名所需的消费者 ID 和私钥。

另外,你能发布你得到的整个错误吗?

他们还有一种新的基于令牌的身份验证方法,这种方法要简单得多。

https://developer.walmart.com/#/apicenter/marketPlace/latest#apiAuthentication

另外,检查 GET 库存是否适用于同一个 sku

---更新----

看起来请求有效负载缺少

<?xml version="1.0" encoding="UTF-8"?>

--- 更新 ---

您的 xml 不符合 xsd 使用这个(删除:ns2)

<?xml version="1.0" encoding="UTF-8"?>
<inventory xmlns="http://walmart.com/">
<sku>Cxxxx2</sku>
<quantity>
<unit>EACH</unit>
<amount>7</amount>
</quantity>
<fulfillmentLagTime>1</fulfillmentLagTime>
</inventory>

【讨论】:

  • 是的,其他 api 工作正常,我在 GetWalmartAuthSignature() 函数中传递了消费者 ID 和私钥。得到 400 HTTP_CODE 作为响应
  • 你得到的错误是什么(整个错误响应)?除了状态代码,它们还在响应中提供错误详细信息
  • 请求的 URL 返回错误:400 Bad Request code : 400
  • 响应中应该有一些错误。尝试使用 Postman 或类似的其他客户端调用相同的调用,看看是否有效
  • 这里 id 邮递员响应:INVALID_REQUEST_CONTENT.GMP_INVENTORY_API com.sun.istack.SAXParseException2;行号:1;列号:1;意外元素(uri:“”,本地:“库存”)。预期的元素是 <{walmart.com}inventory>请求内容无效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-21
  • 2017-10-03
  • 2021-02-03
  • 2021-07-12
  • 2021-10-29
相关资源
最近更新 更多