I'm trying to update price and quantity of my product variant in Shopify using cURL and php below here my code:
$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);
When I test it every time it says :
{"errors":{"variant":"Required parameter missing or invalid"}}
I checked official document https://shopify.dev/docs/admin-api/rest/reference/products/product-variant#update-2020-01 but no luck still. Can someone correct me what is the wrong I'm doing ?
Thanks in advance