Solved

GraphQL Create / Update product with stock information

mattayres
Shopify Partner
11 0 7

Hi guys

 

I am trying to Create (and then update) a simple product with options and stock qty for that variant..

 

I try the below but I get an error: "message": "Argument 'inventoryItem' on InputObject 'ProductVariantInput' has an invalid value ([{cost: \"0.00\", tracked: true}]). Expected type 'InventoryItemInput'.",

 

 

 

mutation {
  productCreate(input: {
         handle:"aaa35daa",
         bodyHtml:"ddf35dd",
         descriptionHtml:"eee35e",
         tags:"dddd, eee,ggg",
         title:"1111Buarton",
         vendor:"Burton",
         options: ["Size", "Color"],
         seo:{
            description:"ttt",
            title:"eeee"
         },
         variants: [
            {
            price:"111",
              inventoryItem: [
				{
					cost: "0.00",
					tracked: true
				}]
              
				inventoryQuantities: [
				{
       			 availableQuantity: 3,
				 locationId: "gid://shopify/Location/62087659605"
            }]
                     
            weight:1,
            sku: "4444345444",
            options: ["S", "Rainbow"]
            },
            
        ]
         published: true
	}
  ) {
    product {
      id
    }
    userErrors {
      field
      message
    }
  }
}

 

 

 

 

 

Accepted Solution (1)

dogowner
Shopify Partner
58 5 8

This is an accepted solution.

My inventoryItem is a dictionary not a list (Python):

             product = {
                #...
                "variants": [
                        #...
                        "inventoryItem": {"tracked": True},
                        "inventoryQuantities": [
                            {
                                "locationId": shopify_location_id,
                                "availableQuantity": quantity,
                            }
                        ],
                    }
                ],
            }

 

 

View solution in original post

Replies 3 (3)

dogowner
Shopify Partner
58 5 8

This is an accepted solution.

My inventoryItem is a dictionary not a list (Python):

             product = {
                #...
                "variants": [
                        #...
                        "inventoryItem": {"tracked": True},
                        "inventoryQuantities": [
                            {
                                "locationId": shopify_location_id,
                                "availableQuantity": quantity,
                            }
                        ],
                    }
                ],
            }

 

 

dogowner
Shopify Partner
58 5 8

Also maybe you are missing commad after inventoryItem as well.  I'm not sure if that is just because you adjust example or not.

mattayres
Shopify Partner
11 0 7

Thanks this got me working now..

 

mutation {
  productCreate(input: {
         title:"Test Product 2",
         vendor:"AEG",
         options: ["Size", "Color"],
         variants: [
            {
            options: ["S", "Rainbow"]
                   inventoryItem: {tracked: true},              
            inventoryQuantities: [
     				 {
       			 availableQuantity: 3,
      		   locationId: "gid://shopify/Location/62087659605"
            }]
            }
          
        ]
		}
  ) {
    product {
      id
    }
    userErrors {
      field
      message
    }
  }
}