Have you tried
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json', 'Accept: application/json', 'Content-Length: 0'));
Also the changing the Content-Length to something other than 0.
Domanda
Morning All,
I am trying to update a SKU's Inventory Level. I am using this URL... (with my store)
https://mystore.mybigcommerce.com/api/v2/products/76/skus/3.json
This works (if i go here and enter credentials I can see the GET data about this SKU.
Now the information about updating inventory level is @ http://developer.bigcommerce.com/docs/api/v2/resources/products/skus#PUT.products.id.skus.id.json
Now my code is as follows...
//Data to Update
$StockdataRAW = array('inventory_level' => 1230);
//Data to update (JSON encoded)
$Stockdata = json_encode($StockdataRAW);
//See the JSON String
var_dump($Stockdata);
$api_url = $BC_Api_Path.'/products/76/skus/3.json';
//Display URL created to test
echo '<a href="'.$api_url.'">'.$api_url.'</a>';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $api_url );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array ('Accept: application/json', 'Content- Length: 0') );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
curl_setopt( $ch, CURLOPT_USERPWD, $BC_Api_User.":".$BC_Api_Token );
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($ch, CURLOPT_POSTFIELDS, $Stockdata);
$response = curl_exec( $ch );
//Just a dump of the response
echo'<pre>';
var_dump($response);
echo'</pre><hr>';
//decode the JSON
$result = json_decode($response);
print_r($result);
I have also tried amending this line...
curl_setopt($ch, CURLOPT_POSTFIELDS, $Stockdata);
To...
curl_setopt($ch, CURLOPT_POSTFIELDS, $StockdataRAW);
&
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($StockdataRAW));
&
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($Stockdata));
The error I get in my VAR_DUMP Response IS....
string '[{"status":415,"message":"The specified input content type is not valid."}]' (length=75)
What Am i doing wrong? I can't figure this out! Many thanks in advance.
Soluzione
Have you tried
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json', 'Accept: application/json', 'Content-Length: 0'));
Also the changing the Content-Length to something other than 0.