使用PHP/CURL的Bigcommerce PUT(库存级别)-错误415输入内容类型无效

使用PHP/CURL的Bigcommerce PUT(库存级别)-错误415输入内容类型无效,php,curl,bigcommerce,Php,Curl,Bigcommerce,早上好 我正在尝试更新SKU的库存水平。 我正在使用这个URL。。。(与我的店铺) 这是有效的(如果我在这里输入凭证,我可以看到关于此SKU的GET数据 现在,有关更新库存级别的信息如下所示@ 现在我的代码如下 //Data to Update $StockdataRAW = array('inventory_level' => 1230); //Data to update (JSON encoded) $Stockdata = json_encode($StockdataRAW);

早上好

我正在尝试更新SKU的库存水平。 我正在使用这个URL。。。(与我的店铺)

这是有效的(如果我在这里输入凭证,我可以看到关于此SKU的GET数据

现在,有关更新库存级别的信息如下所示@

现在我的代码如下

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

&

&

我在VAR_DUMP响应中得到的错误是

 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json', 'Accept: application/json', 'Content-Length: 0'));
我做错了什么?我搞不懂! 非常感谢。你试过了吗


还有将内容长度更改为0以外的内容。

你好,丽莎,谢谢。似乎有帮助,但我现在返回了此错误。
字符串“[{“status”:400,“message”:“此请求需要一个正文,但未提供。”}](长度=86)
例如,如果我将内容长度修改为50,我会得到…
布尔值false
returnedRESOLVED!使用了您的代码,但删除了全部内容位,现在正在处理!
 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));
string '[{"status":415,"message":"The specified input content type is not valid."}]' (length=75)
 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json', 'Accept: application/json', 'Content-Length: 0'));