Product With Multiple Options

I’m Trying To Create A Product With Multiple Product Option Here Is The JSON I’m Using.

API URL : https://xyz.myshopify.com/admin/api/2020-07/products.json

JSON :

{
	"product": {
		"title": "New Product Json",
		"body_html": "XYZ",
		"vendor": "MySHOP",
		"product_type": "",
		"published": true,
		"tags": "test, test new",
		"images": [{
			"src": "https://www.w3schools.com/w3css/img_lights.jpg"
		}],
		"variants": [{
			"title": "26\" x 36\" \/ Horizontal",
			"option1": "26\" x 36\"",
			"option2": "Horizontal",
			"sku": "16127874501899",
			"price": 29.95
		}, {

			"title": "51\" x 60\" \/ Horizontal",
			"option1": "51\" x 60\"",
			"option2": "Horizontal",
			"sku": "16127874501937",
			"price": 39.95
		}, {
			"title": "68\" x 80\" \/ Horizontal",
			"option1": "68\" x 80\"",
			"option2": "Horizontal",
			"sku": "16127874501039",
			"price": 49.95
		}, {
			"title": "88\" x 104\" \/ Horizontal",
			"option1": "88\" x 104\"",
			"option2": "Horizontal",
			"sku": "16127874501145",
			"price": 59.95
		}, {
			"title": "26\" x 36\" \/ Vertical",
			"option1": "26\" x 36\"",
			"option2": "Vertical",
			"sku": "161278745052",
			"price": 29.95
		}, {
			"title": "51\" x 60\" \/ Vertical",
			"option1": "51\" x 60\"",
			"option2": "Vertical",
			"sku": "16127874501494",
			"price": 39.95
		}, {
			"title": "68\" x 80\" \/ Vertical",
			"option1": "68\" x 80\"",
			"option2": "Vertical",
			"sku": "16127874501720",
			"price": 49.95
		}, {
			"title": "88\" x 104\" \/ Vertical",
			"option1": "88\" x 104\"",
			"option2": "Vertical",
			"sku": "16127874501733",
			"price": 59.95
		}]
	},
	"options": [{
		"name": "Size",
		"values": ["26\" x 36\"", "51\" x 60\"", "68\" x 80\"", "88\" x 104\""]
	}, {
		"name": "Alignment",
		"values": ["Horizontal", "Vertical"]
	}]
}

Error:

{
    "errors": {
        "base": [
            "The variant '26\" x 36\"' already exists."
        ]
    }
}

Please Anybody Can Help Me Out To Solve The Error. I’m Confused Where I’m Going Wrong

@hawkscode ,

Happy to help you out with this.

From the code sample provided your options definition falls outside of the product object definition. Move the options definition into the product definition as illustrated below and everything should be fine.

Hope this helps, if you have any questions please don’t hesitate to reach out.

Regards,

John

1 Like

Thanks JCC for help