沃尔玛库存更新无法面对 400

Walmart inventory update not working facing 400

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

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

$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

这正是沃尔玛 api 文档中解释的内容。

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>

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

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

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

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>