chec/commerce.js

Unstable products category_id updating

Closed this issue · 1 comments

I am trying to update a products category_id property using this syntax:
updateProductFromAPI("prod_31q0o3bpNgwDdj", { category_id: "cat_p6dP5gX03ln7kA", });
and it works sometimes, which is not a solution at all, I also tried this syntax:
updateProductFromAPI("prod_31q0o3bpNgwDdj", { product: { description: "some description txt" } });
which also works for properties like "description" for example, but not particularly for category_id.

There is no error though when sending the request. I am using "PUT" request for updating the object.

So my issue is: am I wrong in my approach to do the update and there is something I don't understand, or this is really a problem
from the API? Am I using the right syntax to update the product? And another question is: It seems like API Reference is not completed, like, for example, I would like it to be more specific when describing things in documentation, why not provide some code examples of how to correctly write the "body" request for different use cases? Are there any resources with more specific describing of the API? Or the solution is just contribution to this one? Thank you for attention.

I found the solution, which seem pretty obvious. We can update one, or even more categories ids, as categories property is an array. category_id property (updating only one id) though, can't understand how it works, but it works with categories property, so I will stick to this one.

updateProductFromAPI("prod_31q0o3bpNgwDdj", { categories: [ { id: "cat_p6dP5gX03ln7kA" });