Reputation: 4144
I am using the WooCommerce REST API V3 legacy. I can use their latest API, if necesssary
I am trying to create a product with categories, but the product has none. What is wrong with my request?
POST https://XX.com/taiyi/wc-api/v3/products?consumer_key=XX&consumer_secret=XXHTTP/1.1
Authorization: Basic XX
Content-Type: application/x-www-form-urlencoded
Host: XX.com
Content-Length: 228
Expect: 100-continue
Connection: Keep-Alive
{"product":{"managing_stock":true,"title":"Testing123-1","sku":"Testing123-3","price":0.0,"categories":[{"id":"254","name":"10 needles with tube Bulk Pack","slug":"10-needles-with-tube-bulk-pack"}],"stock_quantity":0,"tags":[]}}
Response
{"product":{"title":"Testing123-1","id":3673,"created_at":"2017-06-08T17:20:05Z","updated_at":"2017-06-08T17:20:05Z","type":"simple","status":"publish","downloadable":false,"virtual":false,"permalink":"https:\/\/amplusclient.com\/taiyi\/product\/testing123-1-3\/","sku":"Testing123-3","price":"","regular_price":"","sale_price":null,"price_html":"<br>","taxable":true,"tax_status":"taxable","tax_class":"","managing_stock":true,"stock_quantity":0,"in_stock":false,"backorders_allowed":false,"backordered":false,"sold_individually":false,"purchaseable":false,"featured":false,"visible":true,"catalog_visibility":"visible","on_sale":false,"product_url":"","button_text":"","weight":null,"dimensions":{"length":"","width":"","height":"","unit":"cm"},"shipping_required":true,"shipping_taxable":true,"shipping_class":"","shipping_class_id":null,"description":"","short_description":"","reviews_allowed":true,"average_rating":"0.00","rating_count":0,"related_ids":[],"upsell_ids":[],"cross_sell_ids":[],"parent_id":0,"categories":[],"tags":[],"images":[{"id":0,"created_at":"2017-06-08T17:20:06Z","updated_at":"2017-06-08T17:20:06Z","src":"https:\/\/amplusclient.com\/taiyi\/wp-content\/plugins\/woocommerce\/assets\/images\/placeholder.png","title":"Placeholder","alt":"Placeholder","position":0}],"featured_src":false,"attributes":[],"downloads":[],"download_limit":-1,"download_expiry":-1,"download_type":"standard","purchase_note":"","total_sales":0,"variations":[],"parent":[],"grouped_products":[],"menu_order":0}}
Upvotes: 1
Views: 4409
Reputation: 1131
It looks like your request would work if you were using the latest version of the API. In the latest version the documentation you can see that your categories object matches theirs. The legacy v3 is a bit different though.
The documentation indicates that you pass the category id's in as a list of integers. It looks like you were trying to include an object with name, slug, and id. I've edited your request below to meet the v3 spec.
{
"product":
{
"managing_stock":true,
"title":"Testing123-1",
"sku":"Testing123-3",
"price":0.0,
"categories":[254],
"stock_quantity":0,
"tags":[]
}
}
Upvotes: 2