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

Create nested categories via API v3 #10147

Closed
lysenko opened this issue Jan 22, 2016 · 4 comments
Closed

Create nested categories via API v3 #10147

lysenko opened this issue Jan 22, 2016 · 4 comments
Labels
needs: author feedback The issue/PR needs a response from any of the parties involved in the issue.

Comments

@lysenko
Copy link

lysenko commented Jan 22, 2016

Congratulations for 2.5 release!
We waited for it and started discovering the API immediately.
Here is the question,
I am trying to create nested categories via API.
When I pass category id as parent, I get woocommerce_api_invalid_product_category_parent
Here https://github.com/woothemes/woocommerce/blob/master/includes/api/class-wc-api-products.php#L676 I noticed that the parent is looked at by term_taxonomy_id. Is the term_taxonomy_id different than the category id that I get from /products/categories endpoint?

@claudiosanches
Copy link
Contributor

Need to be the ID.
Show me your JSON.

@claudiosanches claudiosanches added the needs: author feedback The issue/PR needs a response from any of the parties involved in the issue. label Jan 23, 2016
@claudiosanches
Copy link
Contributor

Well, tested and works fine.

Is the term_taxonomy_id different than the category id that I get from /products/categories endpoint?

Nop, term_taxonomy_id is the category ID, has only one ID for each term.

@lysenko
Copy link
Author

lysenko commented Jan 26, 2016

Sorry for delay, I still have no success.
Unfortunately I cannot share the keys to the company site, here is a curl example without the keys.
curl --insecure https://woocommerce-demo.repairshopr.com/wc-api/v3/products/categories -u ck_XXXXXXXX:cs_XXXXXX
Result:
{"product_categories":[{"id":49,"name":"Clothing","slug":"clothing","parent":0,"description":"","display":"default","image":"","count":0},{"id":47,"name":"Default","slug":"default","parent":0,"description":"","display":"default","image":"","count":0},{"id":46,"name":"Foobar","slug":"foobar","parent":0,"description":"","display":"default","image":"","count":3}, {"id":48,"name":"Prepay Hours","slug":"prepay-hours","parent":0,"description":"","display":"default","image":"","count":0},{"id":50,"name":"Subcategory","slug":"subcategory","parent":1,"description":"","display":"default","image":"","count":0}, {"id":51,"name":"Subcategory","slug":"subcategory-grouped","parent":3,"description":"","display":"default","image":"","count":0}, {"id":52,"name":"Web Created","slug":"web-created","parent":0,"description":"","display":"default","image":"","count":0}, {"id":53,"name":"Web created subcategory","slug":"web-created-subcategory","parent":52,"description":"","display":"default","image":"","count":0}]}

Notice that the first category ID is 46, older category ids were deleted sometime ago.
Notice that there is "Web Created" category and subcategories, I made them in the browser.
Notice that there is {"id":50,"name":"Subcategory","slug":"subcategory","parent":1,"description":"","display":"default","image":"","count":0}
Subcategory created via API for a non exiting parent, it seems that the code is missing logical negative operator somewhere. Or API allow to use only old, non existing category ids as parent.

And finally failing request
curl --insecure -X POST https://woocommerce-demo.repairshopr.com/wc-api/v3/products/categories -u ck_XXXXXXXX:cs_XXXXXXXXX -H "Content-Type: application/json" -d '{ "product_category": { "name": "New Subcategory", "parent": 52 } }'
The response is:
{"errors":[{"code":"woocommerce_api_invalid_product_category_parent","message":"Product category parent is invalid"}]}

@claudiosanches
Copy link
Contributor

Notice that the first category ID is 46, older category ids were deleted sometime ago.

Not a API issue, maybe a problem in our DB.

Subcategory created via API for a non exiting parent, it seems that the code is missing logical negative operator somewhere. Or API allow to use only old, non existing category ids as parent.

The category need to exists.

Seems like a problem in your DB, since we use just WP functions to create and update categories.
I tested and it works fine... It seems you are searching for the problem in the wrong place or using the wrong database (maybe have 2 installations).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: author feedback The issue/PR needs a response from any of the parties involved in the issue.
Projects
None yet
Development

No branches or pull requests

2 participants