Development discussions around Shopify APIs
I am doing a PUT /admin/products/#{id}.json
with the json data containing as an example below.
{"product": {"id" : 138738376, { "variants": [ { "id": 808950810, "inventory_quantity": 10}, {"id": 49148385, "inventory_quantity": 20 } ] } }
After executing the PUT call, the variants in the data are updated, but all the other variants get deleted from the product.
Is this normal or am I doing something wrong here?
Hello Vic, this is expected behaviour. You can keep existing variants by including them in this request as well.
Hey Vic,
That is a good question. You are definitely on the right track for updating inventory for a product variant, but when using that endpoint and writting it the way you had, you are replacing the variant information that is associated with that product ID as opposed to changing just the one you want.
If you want to update product variant inventory quantities, I would recommend you take a look at the PUT /admin/products/#{id}.json endpoint from the document below:
https://docs.shopify.com/api/product#update
Essentially you would need to write out all of the variants in the array so that it updates the ones you want to change, but also keeps the other variants that are on that product.
Hope that points you in the right direction!
Take care,
Nathen
So to be clear, if you do not send every variant id in a product in an UPDATE it DELTES the variant and ALL its data? Does that not seem like a fairly dangerous issue. Once deleted is there anyway to get these products back? Now I used the PUT /admin/products/#{id}.json as you have stated and the OP stated as well. But no where in the documentation that it would delete all the variants. It makes for quite mess for 190 products with 4 variants each. What happened if you have a database of shopify ids and variants, and the product is manually updated or deleted and new variants are created. So due to a manual update an automtic process would delete ALL of that information?
1) Is there a way to get this data back.
2) I think this needs to be added to your API documentation that using a PUT command and not a delete command will delete variants.
Please respond ASAP.
Rgds
Chris
It seems to me using
PUT /admin/variants/#{id}.json would be the safe way to update a single variant at a time.
So using the below, the #{id} is the variant number? and there is no reference to the product id it is a variant of.
Update a variant's inventory using an adjustment
PUT /admin/variants/#{id}.json
{ "variant": { "id": 808950810, "inventory_quantity_adjustment": -5 } }
Update a variant's inventory
PUT /admin/variants/#{id}.json
{ "variant": { "id": 808950810, "inventory_quantity": 100, "old_inventory_quantity": 10 } }
Hi Shayne,
That is the thing, I did not update the product by sending it new variants as in the above example. I tried to update a single variant with a product id and one of its variants that WAS there. It updated the one variant as expected, but it deleted the data for the other variants. Because the remaining calls, calling each produt with one of the variants came back with the variant not found and the data is missing.
So again it looks like if you do not send ALL the variants in the update it deletes the ones you do not send. Obviously the
{ "variant": { "id": 808950810, "inventory_quantity": 100, "old_inventory_quantity": 10 } }
would be direct to the variant and update it. But it really should be documented somewhere when updating if you do not send all the variants, it will delete the other variants not sent.
Rgds
correct, Shopify has one of the worst documentation in the history of documentations xd
User | RANK |
---|---|
10 | |
4 | |
3 | |
3 | |
3 |
We're excited to announce improvements to the threaded messaging experience in our communi...
By TyW May 31, 2023Thank you to everyone who participated in our AMA with Klaviyo. It was great to see so man...
By Jacqui May 30, 2023Photo by Marco Verch Sales channels on Shopify are various platforms where you can sell...
By Ollie May 25, 2023