Proper use of an API endpoint, which endpoint can we use?

BudmilAustria
Visitor
1 0 0
Dear Shopify Community!
 
We need help with the synchronisation script of our webshop. We are currently in the phase where we want to check our already existing variants and then update the variants that are already there but have different data in the database we are comparing (e.g. price, promotion, stock, size)
 
The endpoints we use for this are probably inadequate, because we don't get a normal response back from the CURL log.
 
Query by SKU:
curl_setopt($ch, CURLOPT_URL, "https://$shopUrl/admin/api/2021-07/variants.json?sku=$sku");
 
(Of course we process it and request a variant id to handle further API calls.)
 
To update:
curl_setopt($ch, CURLOPT_URL, "https://$shopUrl/admin/api/2021-07/variants/{$variantData['id']}.json");
 
It's strange to me that for both of them, I found the API endpoint 2021-07 as the correct endpoint in the results, but the documentation says different, or I can't really find in the documentation which one we should use.
 
I would like to ask for your help on this! We would like to find the right API endpoint to communicate with and have further questions.

 

Reply 1 (1)

jdorsch
Tourist
9 2 5

The urls look correct although your version is old.  The request will still work as long as the endpoint action still exists.  (shopify will bump up your 2021-07 version to 2022-10)

 

You should try testing this in a tool such as postman first.  That is by far the best way to verify that the endpoints and payloads you are sending and receiving are correct.

 

After you verify it is working, then you can focus on getting it to work right in your code.  PHP is a finicky beast when it comes to put requests.  If you can get the update endpoint to work in postman then you should ask in a PHP language specific forum.