The variant already exists.

Solved
Highlighted
New Member
3 0 0

I have the following issue:

Seeing a strange error when trying to put variants to a product via the api.

When running the following (https://pastebin.com/ZqEnEGjJ) through an api request on postman I receive this error:

https://gyazo.com/086d67668d33aedacb0e2b45821bab0b


This product only has a default variant so this should be impossible.

If I change the option1 value of variant 2 / 3 to "Pract[something-else]" it will work (so its not anything todo with typos / incorrect api calling that I can tell).

Any suggestions on why this is failing?


Thanks in advance,

0 Likes
Highlighted
Shopify Partner
101 16 22

Hi @ScarletV 

 

Can you try dropping the variant titles from the request, you are using the same ones for the 3 of them and I think that those are the problem?

0 Likes
Highlighted
New Member
3 0 0

Hiya @ikolarov,

Sorry I should have mentioned,

I already tried this, sadly, it doesn't change anything, same error occurs. 

0 Likes
Highlighted
Shopify Partner
101 16 22

This is an accepted solution.

Ok it seems that you need to pass the proper options object to the product.

 

Invalid:

 

  "option1": "PAY",
  "option2": "Type",
  "option3": null,

Valid:

 

"options": [{"name":"PAY"},{"name":"type"}],

Final object should be:

 

{
    "product": {
        "title": "Product name",
        "options": [{"name":"PAY"},{"name":"type"}],
        "variants": [
            {
                "title": "test1",
                "weight": 0.09,
                "weight_unit": "kg",
                "inventory_management": "shopify",
                "inventory_quantity": 15,
                "price": 1,
                "sku": "XT1",
                "option1": "Pract",
                "option2": "test1",
                "option3": ""
            },
            {
                "title": "test2",
                "weight": 0.09,
                "weight_unit": "kg",
                "inventory_management": "shopify",
                "inventory_quantity": 15,
                "price": 1,
                "sku": "XT2",
                "option1": "Pract",
                "option2": "test2",
                "option3": ""
            },
            {
                "title": "test3",
                "weight": 0.09,
                "weight_unit": "kg",
                "inventory_management": "shopify",
                "inventory_quantity": 15,
                "price": 1,
                "sku": "XT3",
                "option1": "Pract",
                "option2": "test3",
                "option3": ""
            }
        ]
    }
}

It worked for me.

1 Like
Highlighted
New Member
3 0 0

Great spot @ikolarov. This indeed was the error, soon as I put that in it works like a charm.

Thanks for helping so quickly!

0 Likes