zhatzid
zhatzid

Reputation: 1

WooCommerce Rest api create/update product variation problem

I am trying to create/update a product variation through rest api and i have a problem.

My product attributes are filled correctly, with options on colour and on size. For example i have these on a product:

“attributes”: [ { “id”: 1, “name”: “χρώμα”, “position”: 0, “visible”: true, “variation”: true, “options”: [ “ΜΠΛΕ” ] }, { “id”: 2, “name”: “μέγεθος”, “position”: 1, “visible”: true, “variation”: true, “options”: [ “52”, “56”, “58”, “60”, “62”, “64”, “66” ] } ],

But when i am trying to fill the attributes on the variation, it returns []. Example of posting:

{ “stock_quantity”: 2, “regular_price”: “22”, “sale_price”: “”, “status”: “publish”, “purchasable”: true, “manage_stock”: true, “attributes”: [ { “id”: 1, “option”: “ΜΠΛΕ” }, { “id”: 2, “option”: “60” } ], “meta_data”: [ { “key”: “Barcode”, “value”: “5207064064442” } ] }

and it returns:

{ “id”: 6225, “date_created”: “2020-04-15T11:19:12”, “date_created_gmt”: “2020-04-15T11:19:12”, “date_modified”: “2020-04-22T17:11:32”, “date_modified_gmt”: “2020-04-22T17:11:32”, “description”: “”, “sku”: “007887”, “price”: “22”, “regular_price”: “22”, “sale_price”: “”, “date_on_sale_from”: null, “date_on_sale_from_gmt”: null, “date_on_sale_to”: null, “date_on_sale_to_gmt”: null, “on_sale”: false, “status”: “publish”, “purchasable”: true, “virtual”: false, “downloadable”: false, “downloads”: [], “download_limit”: -1, “download_expiry”: -1, “tax_status”: “taxable”, “tax_class”: “”, “manage_stock”: true, “stock_quantity”: 2, “stock_status”: “instock”, “backorders”: “no”, “backorders_allowed”: false, “backordered”: false, “weight”: “”, “dimensions”: { “length”: “”, “width”: “”, “height”: “” }, “shipping_class”: “”, “shipping_class_id”: 0, “image”: { “id”: 6192, “date_created”: “2020-04-15T11:17:59”, “date_created_gmt”: “2020-04-15T11:17:59”, “date_modified”: “2020-04-15T11:17:59”, “date_modified_gmt”: “2020-04-15T11:17:59”, }, “attributes”: [], “menu_order”: 0, “meta_data”: [ { “id”: 96831, “key”: “Barcode”, “value”: “5207064064442” } ] }

All the data that i am sending, as stock_quantity, regular_price, meta_data etc are filled corectly. All except attributes.

Any solution?! Thanks

Upvotes: 0

Views: 1870

Answers (1)

gzafaras
gzafaras

Reputation: 11

A little late for the response but you should try to use woocommerce rest api v2 instead of v3 for example {siteUrl}/wp-json/wc/v2/products/{product_id}/variations instead of {siteUrl}/wp-json/wc/v3/products/{product_id}/variations

Upvotes: 1

Related Questions