wordpress WooCommerce REST API使用类别创建产品

5f0d552i  于 2023-06-21  发布在  WordPress
关注(0)|答案(1)|浏览(118)

我使用的是WooCommerce REST API V3 legacy。我可以使用他们最新的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}}
khbbv19g

khbbv19g1#

如果您使用的是最新版本的API,您的请求似乎可以正常工作。在最新版本的文档中,您可以看到您的categories对象与它们的相匹配。不过,Legacy V3有点不同。

WooCommerce REST API v3 Legacy:

文档指出,您将类别id作为整数列表传递。看起来你试图包含一个带有name、slug和id的对象。我已经编辑了下面的请求,以满足v3规格。

{
    "product":
    {
        "managing_stock":true,
        "title":"Testing123-1",
        "sku":"Testing123-3",
        "price":0.0,
        "categories":[254],
        "stock_quantity":0,
        "tags":[]
    }
 }

参考文献

相关问题