我正在使用WooCommerce REST API V3遗产。如果有必要,我可以使用他们最新的API
我正在尝试使用类别创建产品,但产品没有。我的要求有什么问题?
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":[]}}
响应
{"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}}
答案 0 :(得分:0)
如果您使用最新版本的API,看起来您的请求会起作用。在最新版本的documentation中,您可以看到您的类别对象与他们的匹配。传统v3虽然有点不同。
文档表明您将类别ID作为整数列表传递。看起来你试图包含一个名称,slug和id的对象。我在下面编辑了您的请求以符合v3规范。
{
"product":
{
"managing_stock":true,
"title":"Testing123-1",
"sku":"Testing123-3",
"price":0.0,
"categories":[254],
"stock_quantity":0,
"tags":[]
}
}