Search code examples
phpxmlcurlwalmart-api

Walmart inventory update not working facing 400


I'm trying to update walmart inventory using curl api but facing issue with 400 error response code.

Here is my sample code : I followed walmart doc, visited error code related walmart documents and found that they are asking to submit ticket so no solution found publicly.

$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);   

Response : 400

This is what exactly explained in walmart api doc.

P.S: Get inventory, get order and update price working fine with same key and signature. Here is my xml data

 <?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>

Solution

  • Are other APIs working correctly? The reason I ask is because I see that in the sample code for _GetWalmartAuthSignature, you are not passing consumer id and private key, which is needed for generating the signature.

    Also, can you post the entire error you are getting?

    They also have a new token based authentication method which is a lot simpler.

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

    Also, check if GET inventory is working fine or not for the same sku

    ---UPDATE ----

    Looks like the request payload is missing the

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

    --- UPDATE ---

    Your xml was not conforming to the xsd Use this (removing :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>