216 votes
0 answers
php - curl not updating shopify api
Wondering why this code doesn't update my product. I have tested in the chrome rest console and works great. However, when testing the curl in php it doesn't update. I have tested doing a simple GET request for product count with curl in php and it responded fine. Just the PUT is giving me fits. Anything stand out?
<?php
$baseUrl = https://apikey:password@hostname/admin/';
$variant =
array('inventory_quantity' => 20
);
$ch = curl_init($baseUrl.'variants/19175889219.json'); //note product ID in url
$data_string = json_encode(array('variant'=>$variant)); //json encode the product array
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT"); //specify the PUT verb for update
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); //add the data string for the request
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //set return as string true
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
); //set the header as JSON
$server_output = curl_exec ($ch); //execute and store server output
curl_close ($ch); //close the connection
echo $data_string;
echo $server_output;
?>
Undefined asked
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.