[Solved] GraphQL Product Create with Variant Options issue

Solved
Highlighted
Shopify Partner
22 2 13

I'm stuck and theres something i don't understand with the product variant options upon creating a new product with variants.

the options within the variant accepts an array of strings, but whatever i put in that array ends up as values to the title option, what i want todo is to add a size option with values like 42, 43, 45 and so on upon creating the product.

mutation productCreate($input: ProductInput!) {
  productCreate(input: $input) {
    userErrors {
      field
      message
    }
    product {
      id
    }
  }
}

These are the test variables im running with at the moment. (slimmed down version)

{
	"input" : {
		"descriptionHtml" : "Fluffy Description",
		"title" : "Product Title",
		"variants" : [
			{
				"barcode":"123", 
				"options" : [
						"Size"
				]
			}
		]
	}
}

I thought you could do something like:

... 
				"options" : [
					"Size" : ["42","43","44","45"]
				]
...

However when i just add the Size as a single string, it just add is as a value to the title option, but if i then add like 4 strings i'm told i have too many as the limit is 3, which i asume is for the actual options and not the value for the options itself ?

Metafields is a myth...
2 Likes
Highlighted
Shopify Partner
22 2 13

This is an accepted solution.

Figured it out after some rubberduck debugging xD

So you create the options within the product input and give it values within the variant input.
 

{
	"input" : {
		"descriptionHtml" : "Fluffy Description",
		"title" : "Product Title",
		"options" : ["Size"],
		"variants" : [
			{
				"barcode":"123", 
				"options" : [
						"42"
				]
			}
		]
	}
}

 

Metafields is a myth...
8 Likes
Highlighted
New Member
2 1 7

This is an accepted solution.

This just saved my life.

 

Thanks.

 

mutation {
  productCreate(input: {
         handle:"aaaaa",
         bodyHtml:"dddd",
         descriptionHtml:"eeee",
         tags:"dddd, eee,ggg",
         title:"1111Burton",
         vendor:"Burton",
         options: ["Size", "Color"],
         seo:{
            description:"ttt",
            title:"eeee"
         },
         variants: [
            {
            price:"111",
            weight:1,
            sku: "4444444",
            options: ["S", "Rainbow"]
            },
            {
            price:"222",
            weight:1.3,
            sku: "bbb",
            options: ["S", "Blue"]
            },
            {
            price:"333",
            weight:1.3,
            sku: "tttt",
            options: ["M", "Pink"]
            }
        ]
         published: true
	}
  ) {
    product {
      id
    }
    userErrors {
      field
      message
    }
  }
}
2 Likes