我正在尝试在 Shopify 中使用 cURL 和 php 在我的代码下面更新我的产品变体的价格和数量:
$url = $api_url 。'/admin/api/2020-01/variants/31941936382042.json';
$data_json = json_encode(
array(
'variants' => array(
'id' => 4574444978266,
'sku' => 'TEST-SKU-111',
'price' => 20,
'compare_at_price' => 20,
'cost' => 20, // This price will be coming form database
'inventory_quantity' => 10))
);
var_dump($data_json);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($data_json)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
var_dump($response);
curl_close($ch);
当我每次测试时它都会说:
{"errors":{"variant":"必需参数丢失或无效"}}
我检查了官方文档https://shopify.dev/docs/admin-api/rest/reference/products/product-variant#update-2020-01但仍然没有运气。有人可以纠正我我在做什么错吗?
提前致谢