ShopifySharp
ShopifySharp copied to clipboard
Product Services:UpdateAsync - (400 Bad Request) Write requests to inventory_quantity and inventory_quantity_adjustment are no longer supported.
Loading the product using GetAsync, Product product = await productService.GetAsync((long)apiCall.Product.Id); product.Tags = newTags; product = await productService.UpdateAsync((long)product.Id, product);
calling the UpdateAsync gives below error, (400 Bad Request) Write requests to inventory_quantity and inventory_quantity_adjustment are no longer supported. Please use the Inventory Levels API.
Stack trace:
at ShopifySharp.ShopifyService.CheckResponseExceptions(HttpResponseMessage response, String rawResponse) at ShopifySharp.ShopifyService.<>c__DisplayClass26_0
1.<<ExecuteRequestAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at ShopifySharp.DefaultRequestExecutionPolicy.Run[T](CloneableRequestMessage request, ExecuteRequestAsync1 executeRequestAsync) at ShopifySharp.ShopifyService.ExecuteRequestAsync[T](RequestUri uri, HttpMethod method, HttpContent content, String rootElement) at ShopifySharp.ProductService.UpdateAsync(Int64 productId, Product product)
I see that same issue has been raised on the Shopify api ruby gem repo. See https://github.com/Shopify/shopify_api/issues/702
This means it's a bug in Shopify side and not a problem with ShopifySharp.
Please see my comment here.
Thank you @clement911 and @EmmaB
could you please help me to understand how to handle within shopifysharp?
found below threads in shopify, https://community.shopify.com/c/Shopify-APIs-SDKs/400-BadRequest-on-variant-save/m-p/602230/highlight/true#M40797 https://github.com/Shopify/shopify_api/issues/632
@madushann Try this code out.
var productToUpdate = new Product {
Id = product.Id,
Tags = newTags,
PublishedAt = product.PublishedAt ?? product.PublishedAt
};
var result = await productService.UpdateAsync(productToUpdate.Id.Value, productToUpdate);
@mark-jeanswhse Thank you very much.
I am going to try, just wondering will this update the product with missing data ?
@madushann It's possible that it could mess up some product data, since many of the properties you don't set would be serialized as null
. That's why @mark-jeanswhse is using PublishedAt = ...
-- if that one is accidentally set to null, it will unpublish your product.
You should also be able to just set the InventoryQuantity
property to null before you update the product, and that should get it working again.
var product = await productService.GetAsync(productId);
product.Tags = newTags;
product.InventoryQuantity = null;
product = await productService.UpdateAsync(productId, product);
I'm going to publish an update to the ProductService
that will automatically do this behind the scenes for each update call, as I've had a handful of questions and emails about this error. It's too easy for us to accidentally shoot ourselves in the foot when trying to update products thanks to the property deprecation.
Actually "InventoryQuantity" is in the ProductVariant, which need to be set iterating the variant list.
foreach (var variant in product.Variants) { variant.InventoryQuantity = null; }
This worked for me for the moment.
@nozzlegear
I'm going to publish an update to the
ProductService
that will automatically do this behind the scenes for each update call, as I've had a handful of questions and emails about this error. It's too easy for us to accidentally shoot ourselves in the foot when trying to update products thanks to the property deprecation.
Hope, Once you push the update will be available straight forward with newer version.