shopify-api-ruby: Edit product raise error: Bad Request (Write requests to inventory_quantity and inventory_quantity_adjustment are no longer supported. Please use the Inventory Levels API.)
I can’t edit any exist products. Everytime I save one, it raise error:
ActiveResource::BadRequest (Failed. Response code = 400. Response message = Bad Request (Write requests to inventory_quantity and inventory_quantity_adjustment are no longer supported. Please use the Inventory Levels API.).):
Note that I tested by load random product, then edit it’s title only. this issue only appear today, my application still works fine a couple of days ago.
products = ShopifyAPI::Product.find(:all, :params => {:handle => handle})
product = products[0]
product.title = 'New title'
product.save
Here my gemfile config:
gem 'shopify_app', '12.0.5'
gem 'shopify_api', '9.0.1'
API version:
config.api_version = “2020-01”
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 19 (3 by maintainers)
Yes, we had this yesterday: I don’t know what Shopify API change caused it, but it just kicked in yesterday.
The
ShopifyAPI::Product
has attributes such asinventory_quantity
that are no longer writable, so what you have to do when you retrieve the existing record is to get only the attributes that you want to update:Same with the
ShopifyAPI::Variant
.Hope that helps.
@iamkristian ive found even with the new update (v9.0.3) this is still happening. I’m now doing the following
adding that extra line
variant.attributes = variant.attributes.except("inventory_quantity", "old_inventory_quantity")
basically allows the rest of your code to function as it did before.This will be fixed in this PR https://github.com/Shopify/shopify_api/pull/655
@tanema for what it’s worth we just upgraded to 2021-01 and this problem was still persisting. I need to explicity remove
"inventory_quantity", "old_inventory_quantity"
fromattributes
before I am able to save a variant.Worse now though, that the
400 Bad Request
doesn’t actually contain any useful information about what is wrong.Is there any way to get more detailed response information from shopify to debug issues like these?
Thanks.
@tanema is there any update on this issue?
We’ve paused an API migration until this issue was fixed. If the fix is not released in the following weeks we’ll have to resort to implementing the workaround ourselves, so I’d love to have an update so we can plan accordingly. Thanks!
@alex-espinoza I learned that when I call save - the api reloads the full object with all fields. Pretty annoying
Just want to add my experience using the
where
clause. It will give you whatever if you usewhere(id: ...)
.Eventually, I dug this out:
This will give a 404 if not found, and the product if found returning the fields I want.
If I use
where
, it will just take the next available product - highly unexpected behaviour.Thanks again @EmmaB for pointing me in the right direction
Yes, it took a bit of looking through the docs, in the Endpoints section here: https://shopify.dev/docs/admin-api/rest/reference/products/product
@EmmaB Excellent! Thanks a bunch, that really helps. I’ll try that. Didn’t even know could do that