我正在尝试使用 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 中解释的内容。
PS:获取库存,获取订单和更新价格使用相同的密钥和签名工作正常。这是我的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>