• Resolved t71southw

    (@t71southw)


    Hi all,

    I’m trying to create products from a 3rd party source using the REST API and all works well except when it comes to variations. I can get single variations to work, but not combinations of variations.

    The process I am following is:

    1. Create Attributes
    2. Create Attribute Terms
    3. Create Product
    4. Add attributes to product
    4. Add variations based on Attributes

    For a product with a single variation, this works fine (for example, size: small, medium, large).

    Using the API docs, this looks like:

    “regular_price”: “9.00”,
    “image”: {
    “id”: 423
    },
    “attributes”: [
    {
    “id”: 6,
    “option”: “Black”
    }
    ]
    }’

    However, if I have multiple variations – for example size & colour, I cannot figure out how to add the variations through the API (small/blue, small/black, small/red, medium/blue, medium/black, medium/red etc).

    I understand that each attriubute combination has to be a seperate variation – so a variation for:

    small/blue
    small/black
    small/red
    medium/blue
    medium/black
    etc.

    But how to I submit this info in the API?

    “regular_price”: “9.00”,
    “image”: {
    “id”: 423
    },
    “attributes”: [
    {
    “id”: 6, <— tried this as an array of the approrpiate attributes (size, colour)
    “option”: “Black” <— also set this as an array of option values
    }
    ]
    }’

    I’ve searched for examples or others trying to do something similar, but have had no success.

    Anyone any suggestions?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support con

    (@conschneider)

    Engineer

    Hi there,

    But how to I submit this info in the API?

    I would create the product manually once and then look at the GET JSON response wp-json/wc/v3/products/[id].

    Then copy the response body, modify it slightly and send it back as POST to see if that gets accepted.

    Kind regards,

    Thread Starter t71southw

    (@t71southw)

    Thanks Con.

    I followed your suggestion and figured it out (dont know why I didnt think to create it manually and then look at the GET).

    For the record, this works when creating variations with combinations of attributes:

    POST https://zzzzz.com/wp-json/wc/v3/products/1234/variations/batch
    {"create":
    [
       { "regular_price": "18.0000",
         "sku": "12345",
         "attributes":[
              // array of attribute id's & options that identify this variation
                       { "id": 93, "option": "Small"},
                       { "id": 94, "option": "Black"}
                      ]
       },
       { "regular_price": "19.0000",
         "sku": "98765",
         "attributes":[
                       { "id": 93, "option": "Medium"},
                       { "id": 94, "option": "Black"}
                      ]
       }
    ]
    • This reply was modified 4 years, 8 months ago by t71southw.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[REST API] Create Products with multiple variation combinations’ is closed to new replies.