• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

cURL库存更新到Shopify API不起作用

php 来源:Kailas 8次浏览

请检查我的cURL测试代码,并让我知道如果您看到任何执行它的原因不会更新我的产品变体的库存。只有一个产品具有Variant数据,并没有单独的产品变体。所以它应该是非常简单的,对吧?cURL库存更新到Shopify API不起作用

cURL已安装并且在我的盒子上正常工作,并且API密钥/令牌也已验证。

这是我的代码


//Set up access 

$apiKey = "[my api key]"; 
$pwd = "[my pwd]"; 

$baseUrl = $apiKey . $pwd ."@sensible-herbs.myshopify.com/admin/"; 

//Set up test data 

    $variantId = '3744859331'; 
    $inventoryQty = '50'; 

//Set up JSON payload 

$payload = array (   
    "variant" => array("id" => $variantId, 
    " nventory_quantity" => $inventoryQty 
    )    
); 

$payload = json_encode($payload, JSON_NUMERIC_CHECK); 
echo 'JSON payload: ' .$payload ."<p>"; 

$putUrl = $baseUrl ."variants/" ."$variantId".".json"; 
echo 'url: ' .$putUrl ."<hr>"; 

$session = curl_init(); 

curl_setopt($session, CURLOPT_URL, $putUrl); 
curl_setopt($session, CURLOPT_CONNECTTIMEOUT, 30); //seconds to allow for connection 
curl_setopt($session, CURLOPT_TIMEOUT, 30); //seconds to allow for cURL commands 
curl_setopt($session, CURLOPT_HEADER, true); //include header info in return value ? 
curl_setopt($session, CURLOPT_RETURNTRANSFER, true); //return response as a string 
curl_setopt($session, CURLOPT_PUT, 1); 
curl_setopt($session, CURLOPT_POSTFIELDS, $payload); 
curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json')); 

$data = curl_exec($session); 

print_r(curl_getinfo($session)); 

curl_close($session); 

echo $data; // session data 

我正的响应为:

阵列([URL] =>https://[apikey+password]@sensible-herbs.myshopify.com/admin/variants/3744859331.json [内容] => [HTTP_CODE] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.156 [namelookup_time] => 0.078 [connect_time] => 0.156 [pretransfer_time] => 0 [size_upload] => 0 [size_downlo ad] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [certinfo] => Array )[primary_ip] => 23.227.38.71 [primary_port] => 443 [local_ip] => 192.168.0.10 [local_port] => 50573 [redirect_url] =>)

因此,它看起来像是连接,没有得到PUT ……或者我只是不明白API/URL的要求是什么……或者可能存在一些隐藏的或缺少的开关或权限,我需要设置除APIKey以外的其他代码… I希望我知道!

在此先感谢和合十!

凯拉斯


===========解决方案如下:

它看起来就像你在你的有效载荷阵列有一个咒语错误,inventory_quantitynventory_quantity

$payload = array (   
    "variant" => array(
     "id" => $variantId, 
     "inventory_quantity" => $inventoryQty 
    )    
); 

版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)