Solved

GraphQL inventoryItemUpdate Mutation - Updating Cost

Lawson_Thalmann
Shopify Partner
76 0 64

 Hi - I'm trying to update the product cost using the inventoryItemUpdate mutation shown here: https://shopify.dev/api/admin-graphql/2021-10/mutations/inventoryitemupdate 

I've also been careful to use the right decimal format shown here: https://shopify.dev/api/admin-graphql/2021-10/scalars/Decimal 

Here's the code I'm working with:

 

mutation{ 
  inventoryItemUpdate(input: {id: "gid://shopify/Product/6593001324678"}) {
    inventoryItem {
      cost {
        amount: "29.99"
        currencyCode: USD 
      }
    }
  }

 

And, here's the error I get:

 

{
  "errors": [
    {
      "message": "Parse error on \"29.99\" (STRING) at [5, 17]",
      "locations": [
        {
          "line": 5,
          "column": 17
        }
      ]
    }
  ]
}

 

It's probably something simple as I'm new to GraphQL, but I'm out of ideas. Any suggestions?

 

Thanks! 

 

 

Accepted Solution (1)

awwdam
Shopify Staff
249 42 36

This is an accepted solution.

Hey @Lawson_Thalmann

After checking our resource here and looking at the examples, it seems like there are a few missteps in the request. First, you will need to query for inventory_item_id, found on the InventoryItem object. I've included an example to help with formatting your request without separated input variables, which would look something closer to the example below. There is some pretty in-depth documentation available if you are new to GraphQL, specifically this GraphQL Learning Kit from our Partner Blog, especially if you are looking for some formatting examples - Cheers!

mutation {
  inventoryItemUpdate (
    id: "gid://shopify/InventoryItem/{ID}",
    input: {
      cost: "29.99"
    }
  )
  {
    inventoryItem {
      id,
      unitCost {
        amount
      }
    }
    userErrors {
      field,
      message
    }
  }
}

awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 2 (2)

awwdam
Shopify Staff
249 42 36

This is an accepted solution.

Hey @Lawson_Thalmann

After checking our resource here and looking at the examples, it seems like there are a few missteps in the request. First, you will need to query for inventory_item_id, found on the InventoryItem object. I've included an example to help with formatting your request without separated input variables, which would look something closer to the example below. There is some pretty in-depth documentation available if you are new to GraphQL, specifically this GraphQL Learning Kit from our Partner Blog, especially if you are looking for some formatting examples - Cheers!

mutation {
  inventoryItemUpdate (
    id: "gid://shopify/InventoryItem/{ID}",
    input: {
      cost: "29.99"
    }
  )
  {
    inventoryItem {
      id,
      unitCost {
        amount
      }
    }
    userErrors {
      field,
      message
    }
  }
}

awwdam | API Support @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Lawson_Thalmann
Shopify Partner
76 0 64

Hey @awwdam - Okay, very helpful! Thanks. I'm starting to do that GraphQL tutorial. So, in order to reach my goal of updating the cost of a specific sku in our inventory system once the cost changes there, I need to use the sku to query for the inventoryItem ID. That way I can turn around and do the mutation for that ID. This didn't work, but am I on the right track with the below? I'm getting that from the tutorial you sent:

 

{
  inventoryItems(first:10, query=sku:"LOLLIA-10KR16") {
		edges {
            node {
        id
      }
    }
  }
}