Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Re: GraphQL Create / Update product with stock information

Solved

GraphQL Create / Update product with stock information

mattayres
Shopify Partner
11 0 8

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
59 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
59 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
59 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 8

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
    }
  }
}