Hi there!
Here’s the documentation that can get you started with creating product attributes and variations:
https://woocommerce.github.io/woocommerce-rest-api-docs/#create-a-product-attribute
https://woocommerce.github.io/woocommerce-rest-api-docs/#create-a-product-variation
I hope this helps. Feel free to get back to us in case you have any additional questions!
Hi, thank you very much. I already read this. Am I correct:
1. Create Attribute like size, color
2. get those attributes id and add it to the product
Hi @nicodeluxe
Am I correct:
1. Create Attribute like size, color
2. get those attributes id and add it to the product
This approach should ideally get you to achieve this.
Here’s how you can create attributes: https://woocommerce.github.io/woocommerce-rest-api-docs/?php#create-a-product-attribute
Note the variable id that you’ve created from the link above. Then go ahead and create the variation, by following these steps: https://woocommerce.github.io/woocommerce-rest-api-docs/?shell#create-a-product-variation
curl -X POST https://example.com/wp-json/wc/v3/products/22/variations \
-u consumer_key:consumer_secret \
-H "Content-Type: application/json" \
-d '{
"regular_price": "9.00",
"image": {
"id": 423
},
"attributes": [
{
"id": 6,
"option": "Black"
}
]
}'
As you can see:
"attributes": [
{
"id": 6,
"option": "Black"
}
]
is what you can use to add the product attribute name and its id.
I hope this helps!
thank you very much! The Attribute term like “black”, white etc must be added before or is it added automatically?
Hi @nicodeluxe
The Attribute term like “black”, white etc must be added before or is it added automatically?
I would recommend creating attributes first. As mentioned in the previous example I shared, while creating variations, you will need to assign attributes, as mentioned in the following example:
“attributes”: [
{
“id”: 6,
“option”: “Black”
}
]
So, in this case, the "id": 6, comes from the attribute that was created previously, and had the id of 6. Only then can it be assigned to the variation.
I hope that helps!
You are my hero 😀
got it done, thank you very very much!!
Glad to hear that, @nicodeluxe
Since you got this sorted, I’m going to mark this topic as Resolved. Let us know if you keep running into troubles. You can create a new thread to report your troubles to us.
All the best!