I’ve seen a post similar to this one, but I haven’t found the answer yet. Can you please help me?
I’m trying to create a variable product using the woocommerce REST API, but the attributes for the variations don’t seem to be created. These are my steps:
Send a post request for the product of the variable type, specifying 2 attributes (color and size). Here seems to be the issue, because the response shows no attributes and if I go to editing the product, the attributes (color and size) don’t seem to be there. I've tried both global and product level attributes.
Send a post request creating a product variant, using a variation combination from step 1. I get no errors, but the product doesn’t seem to be created, nor the variant appears on my store site or when I edit the product on the website admin.
I’ll post my calls and the responses here, I really hope you can help me. I've tried using the V2 and V3 API, but no difference.
Thanks a lot!!!!
1A: My POST of the variable product:
"name": "CHAPEU HERING FEM",
"slug": "CHAPEU HERING FEM",
"type": "variable",
"description": "CHAPEU HERING FEM",
"short_description": "CHAPEU HERING FEM",
"tags": [
{
"name": "KVTA"
}
],
"sku": "KVTA",
"manage_stock": true,
"categories": [
{
"id": 46
},
{
"id": 47
},
{
"id": 48
}
],
"attributes": [
{
"name": "Size",
"position": 0,
"visible": true,
"variation": true,
"Options": [
"G",
"M"
]
},
{
"name": "Color",
"position": 0,
"visible": true,
"variation": true,
"Options": [
"BEGE"
]
}
]
}
1B: The response I get. Mind that the response doesn’t give me any erros, but it doesn’t return the attributes either.
"id": 1500,
"name": "CHAPEU HERING FEM",
"slug": "chapeu-hering-fem",
"permalink": "https://woocriar.com/product/chapeu-hering-fem/",
"date_created": "2021-03-22T12:32:46",
"date_created_gmt": "2021-03-22T12:32:46",
"date_modified": "2021-03-22T12:32:46",
"date_modified_gmt": "2021-03-22T12:32:46",
"type": "variable",
"status": "publish",
"featured": false,
"catalog_visibility": "visible",
"description": "CHAPEU HERING FEM",
"short_description": "CHAPEU HERING FEM",
"sku": "KVTA",
"price": "",
"regular_price": "",
"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,
"purchasable": false,
"total_sales": 0,
"virtual": false,
"downloadable": false,
"downloads": [],
"download_limit": -1,
"download_expiry": -1,
"external_url": "",
"button_text": "",
"tax_status": "taxable",
"tax_class": "",
"manage_stock": true,
"stock_quantity": null,
"backorders": "no",
"backorders_allowed": false,
"backordered": false,
"sold_individually": false,
"weight": "",
"dimensions": {
"length": "",
"width": "",
"height": ""
},
"shipping_required": true,
"shipping_taxable": true,
"shipping_class": "",
"shipping_class_id": 0,
"reviews_allowed": true,
"average_rating": "0",
"rating_count": 0,
"upsell_ids": [],
"cross_sell_ids": [],
"parent_id": 0,
"purchase_note": "",
"categories": [
{
"id": 46,
"name": "ACESSÓRIO",
"slug": "acessorio"
},
{
"id": 47,
"name": "CHAPÉU",
"slug": "chapeu"
},
{
"id": 48,
"name": "Feminino",
"slug": "feminino"
}
],
"tags": [],
"images": [],
"attributes": [],
"default_attributes": [],
"variations": [],
"grouped_products": [],
"menu_order": 0,
"price_html": "",
"related_ids": [],
"meta_data": [],
"stock_status": "outofstock",
"_links": {
"self": [
{
"href": "https://woocriar.com/wp-json/wc/v3/products/1500"
}
],
"collection": [
{
"href": "https://woocriar.com/wp-json/wc/v3/products"
}
]
}
}
2A: My post of a product variant
"sku": "0001047123",
"regular_price": "65.90",
"manage_stock": true,
"status": "publish",
"stock_quantity": 1,
"attributes": [
{
"name": "Size",
"option": "G"
},
{
"name": "Color",
"option": "BEGE"
}
]
}
2B. The response I get. It seems ok, but it doesn’t show on my store nor when I try to edit the product.
"id": 1501,
"date_created": "2021-03-22T12:34:37",
"date_created_gmt": "2021-03-22T12:34:37",
"date_modified": "2021-03-22T12:34:37",
"date_modified_gmt": "2021-03-22T12:34:37",
"description": "",
"permalink": "https://woocriar.com/product/chapeu-hering-fem/",
"sku": "0001047123",
"price": "65.90",
"regular_price": "65.90",
"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": 1,
"stock_status": "instock",
"backorders": "no",
"backorders_allowed": false,
"backordered": false,
"weight": "",
"dimensions": {
"length": "",
"width": "",
"height": ""
},
"shipping_class": "",
"shipping_class_id": 0,
"image": null,
"attributes": [],
"menu_order": 0,
"meta_data": [],
"_links": {
"self": [
{
"href": "https://woocriar.com/wp-json/wc/v3/products/1500/variations/1501"
}
],
"collection": [
{
"href": "https://woocriar.com/wp-json/wc/v3/products/1500/variations"
}
],
"up": [
{
"href": "https://woocriar.com/wp-json/wc/v3/products/1500"
}
]
}
}