I am getting the deprecation warning "compare_at_price must always be higher than price" in the Variant API endpoint. In an effort to fix it we blank out the compare_at_price (NULL) when it is no longer relevant to our pricing (i.e. when our pricing changes and now exceeds the compare_at_price). However, I still receive deprecation warnings, and cannot figure out how to blank out compare_at_price and change the price in the same API call. The problem I am seeing can be reproduced as follows:
1. Product has a price and compare_at_price already set. I will use $320 as the price and $330 as compare_at_price.
2. Product price has increased to $350, and since this is now above the compare_at_price, I need to set the new price and blank out the compare_at_price since it's no longer relevant.
3. Hit the Variants API endpoint with price: 350.00, compare_at_price: NULL
4. This produces the deprecation notice "compare_at_price must always be higher than price"
Strangely enough if the price hasn't changed but i just want to blank out the compare_at_price, I don't get the deprecation warning. i.e. in above scenario setting the price to $320 (same as it already was), and compare_at_price to NULL does NOT product the deprecation notice. It seems to be checking the new price against the OLD compare_at_price rather than the new compare_at_price.
This appears to be a bug, in that I cannot clear out a compare_at_price and change the price at the same time.
Please let me know what to do. Adding an additional API call sending in ONLY the compare_at_price=NULL before adjusting the price will avoid the deprecation notice, however we are then doubling the number of API Variant endpoint calls in our app, and with almost 30k products that is not an option.
Can you confirm which API version you're using? It's possible to see a deprecation error in the response if you're calling an older version and the response includes the field with deprecated behaviour. Updating your calls to use a new version should resolve it. If you're still seeing the warning while using a newer version, please provide the X-Request-ID value from the response headers and we'll investigate further.
Thanks for the response. I am specifying the API version in the url of the request as 2021-01. This is the same version returned in the x-shopify-api-version header response. The x-request-id for a sample call (from our Dev store) is: afcd570c-bcc9-4392-8348-d3acc68ce158
Thanks for your help!
Thanks for providing that. I checked the logs and I'm not exactly sure why your call is being marked as breaking. I made the exact same call myself using Postman and wasn't able to replicate. I'll raise this with our devs for further investigation. Can you let me know which client you're using to send these calls?
We are using our own custom REST API client.
I went ahead and setup Postman and was able to replicate the same problem. The important thing is that the new "price" field must be set ABOVE the OLD compare_at_price, and the new compare_at_price should be set to NULL. Then the API seems to compare the new price against the OLD compare_at_price rather than the new one. In my test i had the product variant price initially set to $320, and the compare_at_price $349.99. Then using Postman I set the price to $350.99 (above the OLD compare_at_price), and the new compare_at_price to NULL. This causes the deprecation warning. Shopify should NOT be comparing my new price to the OLD compare_at_price, since I'm setting a new compare_at_price to Null in the API call. See screenshot below: