Anchor to section titled 'undefined'

inventoryItemUpdate
mutation

Requires write_inventory access scope. Also: The user must have a permission to update an inventory item.

Updates an inventory item.


Anchor to id
id
required

The ID of the inventory item to update.

The input fields that update an inventoryItem.


Was this section helpful?

The inventory item that was updated.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
Copy
mutation inventoryItemUpdate($id: ID!, $input: InventoryItemInput!) {
  inventoryItemUpdate(id: $id, input: $input) {
    inventoryItem {
      id
      unitCost {
        amount
      }
      tracked
      countryCodeOfOrigin
      provinceCodeOfOrigin
      harmonizedSystemCode
      countryHarmonizedSystemCodes(first: 1) {
        edges {
          node {
            harmonizedSystemCode
            countryCode
          }
        }
      }
    }
    userErrors {
      message
    }
  }
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation inventoryItemUpdate($id: ID!, $input: InventoryItemInput!) { inventoryItemUpdate(id: $id, input: $input) { inventoryItem { id unitCost { amount } tracked countryCodeOfOrigin provinceCodeOfOrigin harmonizedSystemCode countryHarmonizedSystemCodes(first: 1) { edges { node { harmonizedSystemCode countryCode } } } } userErrors { message } } }",
 "variables": {
    "id": "gid://shopify/InventoryItem/43729076",
    "input": {
      "cost": 145.89,
      "tracked": false,
      "countryCodeOfOrigin": "US",
      "provinceCodeOfOrigin": "OR",
      "harmonizedSystemCode": "621710",
      "countryHarmonizedSystemCodes": [
        {
          "harmonizedSystemCode": "6217109510",
          "countryCode": "CA"
        }
      ]
    }
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation inventoryItemUpdate($id: ID!, $input: InventoryItemInput!) {
    inventoryItemUpdate(id: $id, input: $input) {
      inventoryItem {
        id
        unitCost {
          amount
        }
        tracked
        countryCodeOfOrigin
        provinceCodeOfOrigin
        harmonizedSystemCode
        countryHarmonizedSystemCodes(first: 1) {
          edges {
            node {
              harmonizedSystemCode
              countryCode
            }
          }
        }
      }
      userErrors {
        message
      }
    }
  }`,
  {
    variables: {
      "id": "gid://shopify/InventoryItem/43729076",
      "input": {
        "cost": 145.89,
        "tracked": false,
        "countryCodeOfOrigin": "US",
        "provinceCodeOfOrigin": "OR",
        "harmonizedSystemCode": "621710",
        "countryHarmonizedSystemCodes": [
          {
            "harmonizedSystemCode": "6217109510",
            "countryCode": "CA"
          }
        ]
      }
    },
  },
);

const data = await response.json();
session = ShopifyAPI::Auth::Session.new(
  shop: "your-development-store.myshopify.com",
  access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
  session: session
)

query = <<~QUERY
  mutation inventoryItemUpdate($id: ID!, $input: InventoryItemInput!) {
    inventoryItemUpdate(id: $id, input: $input) {
      inventoryItem {
        id
        unitCost {
          amount
        }
        tracked
        countryCodeOfOrigin
        provinceCodeOfOrigin
        harmonizedSystemCode
        countryHarmonizedSystemCodes(first: 1) {
          edges {
            node {
              harmonizedSystemCode
              countryCode
            }
          }
        }
      }
      userErrors {
        message
      }
    }
  }
QUERY

variables = {
  "id": "gid://shopify/InventoryItem/43729076",
  "input": {
    "cost": 145.89,
    "tracked": false,
    "countryCodeOfOrigin": "US",
    "provinceCodeOfOrigin": "OR",
    "harmonizedSystemCode": "621710",
    "countryHarmonizedSystemCodes": [{"harmonizedSystemCode"=>"6217109510", "countryCode"=>"CA"}]
  }
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation inventoryItemUpdate($id: ID!, $input: InventoryItemInput!) {
      inventoryItemUpdate(id: $id, input: $input) {
        inventoryItem {
          id
          unitCost {
            amount
          }
          tracked
          countryCodeOfOrigin
          provinceCodeOfOrigin
          harmonizedSystemCode
          countryHarmonizedSystemCodes(first: 1) {
            edges {
              node {
                harmonizedSystemCode
                countryCode
              }
            }
          }
        }
        userErrors {
          message
        }
      }
    }`,
    "variables": {
      "id": "gid://shopify/InventoryItem/43729076",
      "input": {
        "cost": 145.89,
        "tracked": false,
        "countryCodeOfOrigin": "US",
        "provinceCodeOfOrigin": "OR",
        "harmonizedSystemCode": "621710",
        "countryHarmonizedSystemCodes": [
          {
            "harmonizedSystemCode": "6217109510",
            "countryCode": "CA"
          }
        ]
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation inventoryItemUpdate($id: ID!, $input: InventoryItemInput!) {
    inventoryItemUpdate(id: $id, input: $input) {
      inventoryItem {
        id
        unitCost {
          amount
        }
        tracked
        countryCodeOfOrigin
        provinceCodeOfOrigin
        harmonizedSystemCode
        countryHarmonizedSystemCodes(first: 1) {
          edges {
            node {
              harmonizedSystemCode
              countryCode
            }
          }
        }
      }
      userErrors {
        message
      }
    }
  }
QUERY;

$variables = [
  "id" => "gid://shopify/InventoryItem/43729076",
  "input" => [
    "cost" => 145.89,
    "tracked" => false,
    "countryCodeOfOrigin" => "US",
    "provinceCodeOfOrigin" => "OR",
    "harmonizedSystemCode" => "621710",
    "countryHarmonizedSystemCodes" => [{"harmonizedSystemCode"=>"6217109510", "countryCode"=>"CA"}],
  ],
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "id": "gid://shopify/InventoryItem/43729076",
  "input": {
    "cost": 145.89,
    "tracked": false,
    "countryCodeOfOrigin": "US",
    "provinceCodeOfOrigin": "OR",
    "harmonizedSystemCode": "621710",
    "countryHarmonizedSystemCodes": [
      {
        "harmonizedSystemCode": "6217109510",
        "countryCode": "CA"
      }
    ]
  }
}
Hide code
Response
JSON
{
  "inventoryItemUpdate": {
    "inventoryItem": {
      "id": "gid://shopify/InventoryItem/43729076",
      "unitCost": {
        "amount": "145.89"
      },
      "tracked": false,
      "countryCodeOfOrigin": "US",
      "provinceCodeOfOrigin": "OR",
      "harmonizedSystemCode": "621710",
      "countryHarmonizedSystemCodes": {
        "edges": [
          {
            "node": {
              "harmonizedSystemCode": "6217109510",
              "countryCode": "CA"
            }
          }
        ]
      }
    },
    "userErrors": []
  }
}