R
R
Romaleg2021-11-30 13:31:28
API
Romaleg, 2021-11-30 13:31:28

How to write attributes to JSON when creating variations via Rest API?

The problem is, adding products via the API is configured, and it seemed to work fine, I don’t know for sure, but now the point is that the product is created normally via the API, attributes are also added normally, but I can’t create variations from specific attributes .

{
    "type": "variable",
    "name": "My product 1",
    "description": "My product description 1",
    "regular_price": "200",
    "short_description": "Мое описание",
    "images": [
        {
            "src": "http://demo.woothemes.com/woocommerce/wp-content/uploads/sites/56/2013/06/T_2_front.jpg"
        }
    ],
    "attributes": [
        {
            "id": 37,
            "name": "Фасовка",
            "slug": "pa_фасовка",
            "type": "nasa_label",
            "visible": true,
            "variation": true,
            "options": ["Коробка", "Штука"]
        }
    ]
}

Here is the creation of the product, at this stage all the rules, the attributes are added.
Next comes the request for
/wp-json/wc/v3/products//variations/
{
    "regular_price": "150",
    "attributes": [
        {
            "id": 37,
            "name": "Фасовка",
            "option": "Коробка"
        }
    ]
}

and nothing, i.e. other values ​​change normally, like description, price, no problem, but the attributes are always returned empty, although according to all the documentation, with such a request, everything comes back normally. Moreover, if you create a product through the admin panel and add variations manually, then all the rules are added and when requested, they come as they should
. Here is the answer that comes when working through the API:
"attributes": [],
and this is when manually adding:
"attributes": [
        {
            "id": 37,
            "name": "фасовка",
            "option": "%d1%88%d1%82%d1%83%d0%ba%d0%b0"
        }
    ],

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Romaleg, 2021-12-01
@Romaleg

I figured it out, it was in the name of the label for the attribute, it should be in Latin)

A
azeakm, 2021-12-02
@azeakm

aze akm

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question