Update inventory quantity using REST API for product with no variants

Update inventory quantity using REST API for product with no variants

browntaped
Tourist
7 0 4

We have few products in our store which do not have variants. Shopify seems to assign a "default variant" for such products. We are trying to update the quantity of the inventory using the REST API as follows

update_inventory_req = requests.post( "https://%s.myshopify.com/admin/api/%s/inventory_levels/adjust.json" % (SHOP_NAME, API_VERSION), auth=(API_KEY,PASSWORD), json=json.dumps(payload), headers={'Content-Type': 'application/json'}

Where payload is

payload = {"inventory_item_id":14094647492653, "location_id":29563841,"available":1}

 However, we are getting the status code as follows:

(Pdb) update_inventory_req
<Response [403]>
(Pdb) update_inventory_req.reason
'Forbidden'
(Pdb)

FYI:  The above approach works for products which have variants.

Is there anything special to be done for products with no variants?

Reply 1 (1)

_JB
Shopify Staff (Retired)
836 100 223

Hey @browntaped,

Http status 403 is usually due to an invalid API key/API secret being used, so it's odd that it's only happening for requests where products have just the default variant. If you can provide the X-Request-ID value from the response headers of your failed calls, I can use that to try and find more information about the error.

JB | Solutions Engineer @ Shopify 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog