2

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>
mukesh
  • 33
  • 8
  • Have you double checked that your `$data`-variable contains the correct fields? It's hard for us to help you debug this since we don't know what data you're posting. – M. Eriksson Oct 11 '18 at 13:49
  • @MagnusEriksson i updated question with data. – mukesh Oct 11 '18 at 13:52

1 Answers1

0

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>
kushan85
  • 102
  • 1
  • 9
  • 1
    yes other api working fine and i pass consumer id and private key inside GetWalmartAuthSignature() function. getting 400 HTTP_CODE as response – mukesh Oct 12 '18 at 05:22
  • What is the error you are getting (entire error response)? Along with status code, they also provide error details in the response – kushan85 Oct 12 '18 at 05:25
  • The requested URL returned error: 400 Bad Request code : 400 – mukesh Oct 12 '18 at 05:33
  • There should be some error in the response. Try invoking the same call using a rest client like Postman or something similar and see if that works – kushan85 Oct 12 '18 at 05:35
  • Here id postman response : INVALID_REQUEST_CONTENT.GMP_INVENTORY_API com.sun.istack.SAXParseException2; lineNumber: 1; columnNumber: 1; unexpected element (uri:"", local:"inventory"). Expected elements are <{http://walmart.com/}inventory> Request content is invalid. – mukesh Oct 12 '18 at 05:56
  • I believe, your xml is missing at the top of the payload. Looks like their sample payload is wrong. If that works, mark this as the correct answer – kushan85 Oct 12 '18 at 06:02