我试图更新沃尔玛库存使用curl,但面临400错误响应代码的问题。
下面是我的示例代码:我跟踪了沃尔玛的文档,访问了与沃尔玛相关的错误代码,发现他们要求提交罚单,所以没有公开的解决方案。
$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文档中所解释的。
获得库存,获得订单,更新价格,使用相同的密钥和签名,工作正常。这是我的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>发布于 2018-10-12 05:20:56
其他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>https://stackoverflow.com/questions/52761631
复制相似问题