Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product Services:UpdateAsync - (400 Bad Request) Write requests to inventory_quantity and inventory_quantity_adjustment are no longer supported. #484

Open
madushann opened this issue Mar 17, 2020 · 8 comments
Labels
bug missing or invalid properties stale Issues that have become inactive and need attention/review from @nozzlegear

Comments

@madushann
Copy link

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_01.<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)

@clement911
Copy link
Collaborator

I see that same issue has been raised on the Shopify api ruby gem repo.
See Shopify/shopify-api-ruby#702

This means it's a bug in Shopify side and not a problem with ShopifySharp.

@EmmaB
Copy link

EmmaB commented Mar 18, 2020

Please see my comment here.

@madushann
Copy link
Author

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
Shopify/shopify-api-ruby#632

@markus-24
Copy link

markus-24 commented Mar 18, 2020

@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);

@madushann
Copy link
Author

@mark-jeanswhse Thank you very much.

I am going to try, just wondering will this update the product with missing data ?

@nozzlegear
Copy link
Owner

@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.

@madushann
Copy link
Author

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.

@madushann
Copy link
Author

@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.

@nozzlegear nozzlegear removed the 5.0 label Jan 25, 2024
@Laurabee530 Laurabee530 added the stale Issues that have become inactive and need attention/review from @nozzlegear label Jan 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug missing or invalid properties stale Issues that have become inactive and need attention/review from @nozzlegear
Projects
None yet
Development

No branches or pull requests

6 participants