早上好,
我正在尝试更新SKU的库存水平。 我正在使用此URL ...(与我的商店)
https://mystore.mybigcommerce.com/api/v2/products/76/skus/3.json
这是有效的(如果我去这里并输入凭据,我可以看到有关此SKU的GET数据。
现在有关更新库存水平的信息是@ http://developer.bigcommerce.com/docs/api/v2/resources/products/skus#PUT.products.id.skus.id.json
现在我的代码如下......
//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);
我也试过修改这条线......
curl_setopt($ch, CURLOPT_POSTFIELDS, $Stockdata);
要...
curl_setopt($ch, CURLOPT_POSTFIELDS, $StockdataRAW);
&安培;
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($StockdataRAW));
&安培;
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($Stockdata));
我在VAR_DUMP响应中得到的错误是......
string '[{"status":415,"message":"The specified input content type is not valid."}]' (length=75)
我做错了什么?我无法解决这个问题! 非常感谢提前。
答案 0 :(得分:2)
你试过吗
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json', 'Accept: application/json', 'Content-Length: 0'));
同时将Content-Length更改为0以外的其他内容。