Skip to content

Shopify Inventory XML (GraphQL)

The XML format documented here is used for the update of inventory levels and inventory items in Shopify, via the Import Inventory task.

The ZynkExternalId field can be populated with a unique ID for the inventory update from the external system. Zynk uses this field in conjunction with the 'Prevent Reprocessing' setting, which is disabled by default on this task. If Id is not provided and the ZynkExternalId has been processed before, the inventory item ID stored by Zynk is used.

XML

Any fields not documented below are ignored by the task. Examples of where in the XML the fields should appear are shown in the samples below.

<?xml version="1.0" encoding="utf-8"?>
<Inventories>
  <Inventory>
    <Sku>MEREXC1</Sku>
    <InventoryItem>
      <Cost>29.99</Cost>
      <CountryCodeOfOrigin>GB</CountryCodeOfOrigin>
      <HarmonizedSystemCode>660320</HarmonizedSystemCode>
      <CountryHarmonizedSystemCodes>
        <CountryHarmonizedSystemCodeInput>
          <CountryCode>US</CountryCode>
          <HarmonizedSystemCode>6603203000</HarmonizedSystemCode>
        </CountryHarmonizedSystemCodeInput>
      </CountryHarmonizedSystemCodes>
      <Measurement>
        <Weight>
          <Unit>KILOGRAMS</Unit>
          <Value>0.5</Value>
        </Weight>
      </Measurement>
      <RequiresShipping>true</RequiresShipping>
      <Tracked>true</Tracked>
    </InventoryItem>
    <InventoryLevel>
      <Name>available</Name>
      <Reason>correction</Reason>
      <Quantities>
        <Quantity>
          <LocationName>Newcastle</LocationName>
          <Quantity>96</Quantity>
        </Quantity>
      </Quantities>
    </InventoryLevel>
  </Inventory>
</Inventories>

In each of the following sections most of the XML has been omitted to make the samples easier to read. The whole structure of the Inventories schema is used above as a reference of where fields should be in the object model.

Inventory

Each record must contain an InventoryItem, an InventoryLevel, or both. The inventory item is identified by Id, or by Sku if no Id is provided. When matching by Sku, every inventory item in Shopify with that SKU is updated.

Shopify Field XML Field Type Input Notes
- ZynkExternalId string Optional Stored in Zynk's internal DB and used in conjunction with the 'Prevent Reprocessing' setting
InventoryItem.id Id string Dependant Required if Sku is not provided. Must be the inventory item GraphQL ID (gid://shopify/InventoryItem/123), not the variant ID
InventoryItem.sku Sku string Dependant Required if Id is not provided
<?xml version="1.0" encoding="utf-8"?>
<Inventories>
  <Inventory>
    <ZynkExternalId>MEREXC1</ZynkExternalId>
    <Id>gid://shopify/InventoryItem/19177384016</Id>
    <Sku>MEREXC1</Sku>
  </Inventory>
</Inventories>

Inventory Item

Updates the inventory item using Shopify's inventoryItemUpdate mutation. All fields are optional, and any omitted are left unchanged.

Shopify Field XML Field Type Input Notes
cost Cost decimal Optional Unit cost of the item
sku Sku string Optional Changes the SKU of the inventory item
tracked Tracked bool Optional Whether Shopify tracks inventory for the item
requiresShipping RequiresShipping bool Optional
countryCodeOfOrigin CountryCodeOfOrigin string Optional Two letter ISO country code, e.g. GB
provinceCodeOfOrigin ProvinceCodeOfOrigin string Optional
harmonizedSystemCode HarmonizedSystemCode string Optional
countryHarmonizedSystemCodes.countryCode CountryHarmonizedSystemCodes/CountryHarmonizedSystemCodeInput/CountryCode string Optional
countryHarmonizedSystemCodes.harmonizedSystemCode CountryHarmonizedSystemCodes/CountryHarmonizedSystemCodeInput/HarmonizedSystemCode string Optional
measurement.weight.unit Measurement/Weight/Unit enum Optional GRAMS, KILOGRAMS, OUNCES or POUNDS
measurement.weight.value Measurement/Weight/Value decimal Optional
<?xml version="1.0" encoding="utf-8"?>
<Inventories>
  <Inventory>
    <InventoryItem>
      <Cost>29.99</Cost>
      <Tracked>true</Tracked>
      <RequiresShipping>true</RequiresShipping>
      <CountryCodeOfOrigin>GB</CountryCodeOfOrigin>
      <ProvinceCodeOfOrigin>GB-NBL</ProvinceCodeOfOrigin>
      <HarmonizedSystemCode>660320</HarmonizedSystemCode>
      <CountryHarmonizedSystemCodes>
        <CountryHarmonizedSystemCodeInput>
          <CountryCode>US</CountryCode>
          <HarmonizedSystemCode>6603203000</HarmonizedSystemCode>
        </CountryHarmonizedSystemCodeInput>
      </CountryHarmonizedSystemCodes>
      <Measurement>
        <Weight>
          <Unit>KILOGRAMS</Unit>
          <Value>0.5</Value>
        </Weight>
      </Measurement>
    </InventoryItem>
  </Inventory>
</Inventories>

Inventory Level

Sets stock quantities using Shopify's inventorySetQuantities mutation.

Shopify Field XML Field Type Input Notes
name Name string Required available or on_hand (case-sensitive)
reason Reason string Optional Defaults to correction. Must be one of Shopify's inventory change reasons
referenceDocumentUri ReferenceDocumentUri string Optional A URI describing the cause of the change, e.g. gid://shopify/Order/123
- @IdempotencyKey string Optional Attribute on InventoryLevel. Shopify ignores a repeat request with the same key. A new key is generated if not provided
<?xml version="1.0" encoding="utf-8"?>
<Inventories>
  <Inventory>
    <InventoryLevel IdempotencyKey="79a0e5f5-8454-4369-befa-8d9b8fe7efe2">
      <Name>available</Name>
      <Reason>correction</Reason>
      <ReferenceDocumentUri>gid://shopify/Order/1974482927638</ReferenceDocumentUri>
    </InventoryLevel>
  </Inventory>
</Inventories>

Quantities

At least one Quantity must be provided. If LocationId is not provided, the location is looked up by LocationName, and the record fails if no location is found.

Shopify Field XML Field Type Input Notes
quantities.locationId LocationId string Dependant Required if LocationName is not provided, e.g. gid://shopify/Location/123
- LocationName string Dependant Required if LocationId is not provided
quantities.quantity Quantity int Required The new quantity
quantities.changeFromQuantity ChangeFromQuantity int Optional The quantity expected in Shopify before the change. If provided and it doesn't match, Shopify rejects the update. CompareQuantity is accepted as an alias
<?xml version="1.0" encoding="utf-8"?>
<Inventories>
  <Inventory>
    <InventoryLevel>
      <Quantities>
        <Quantity>
          <LocationId>gid://shopify/Location/16144367705</LocationId>
          <ChangeFromQuantity>95</ChangeFromQuantity>
          <Quantity>96</Quantity>
        </Quantity>
        <Quantity>
          <LocationName>Newcastle</LocationName>
          <Quantity>12</Quantity>
        </Quantity>
      </Quantities>
    </InventoryLevel>
  </Inventory>
</Inventories>