Tracking inventory items

Highlighted
Shopify Partner
7 0 1

Hi,

 

I'm trying to understand how I can enable inventory tracking for products that are created/updated using the GraphQL API.

 

The behaviour I'm seeing is:

 

Product is created with tracking enabled, inventory quantity is supplied for location A.

 

Product is updated with tracking still enabled, inventory quantity is supplied for locations A & B.

 

In the admin website, inventory tracking is only enabled for location A still. In order to start tracking location B, I have go into the variant edit and add the location in 'Edit Locations'.

 

What I want is for tracking to be enabled for all the inventory items I specify during the update, not just the ones that were present when created.

 

Is this possible through the API?

 

{
    "query": "mutation productUpdate($input: ProductInput!) { productUpdate(input: $input) { userErrors { field message } product { id metafields(first: 1) { edges { node { id description } } } variants(first: 10) { edges { node { id inventoryPolicy inventoryItem { id tracked inventoryLevels(first: 10) { edges { node { id available location { name } } } } } inventoryQuantity } } } } } }",
    "variables": {
        "input": {
            "id": "gid://shopify/Product/4451131752579",
            "title": "A Test Product BLACK",
            "vendor": "Bagheera",
            "options": [
                "Color",
                "Size"
            ],
            "variants": [
                {
                    "barcode": "0000010002727",
                    "sku": "241113015-005",
                    "options": [
                        "BLACK",
                        "XS"
                    ],
                    "price": 611.25,
                    "compareAtPrice": 689.00,
                    "weight": 0,
                    "weightUnit": "GRAMS",
                    "inventoryItem": {
                        "cost": 249.00,
                        "tracked": true
                    },
                    "inventoryManagement": "SHOPIFY",
                    "inventoryQuantities": [
                        {
                            "locationId": "gid://shopify/Location/37684183171",
                            "availableQuantity": 8
                        },
                        {
                            "locationId": "gid://shopify/Location/37684314243",
                            "availableQuantity": 9
                        }
                    ]
                }
            ]
        }
    }
}

 

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 170

Hey @Jason_Whetton,

 

Can you provide the query you're using to create the product?

Notice; Out of office, replies will be delayed until my return. Thanks!
0 Likes
Highlighted
Shopify Partner
7 0 1

Sure.

 

Note that we have now added inventory quantities for all locations that exist in Shopify with 0 in order for tracking to be enabled. Previously we did not do this. I don't understand why that should be necessary in order for tracking to be enabled on those locations.

 

What would happen if we created a new location in Shopify after creating the products? I would expect tracking to get enabled for all locations with a quantity set in the inventoryQuantities array, but this does not appear to happen.

 

It's not clear to me either why Tracked is set at the variant level, yet appears to be a setting that is specific per variant/location.

 

{
    "query": "mutation productCreate($input: ProductInput!) { productCreate(input: $input) { product { id metafields(first: 1) { edges { node { key value } } } } userErrors { message field } } }",
    "variables": {
        "input": {
            "title": "ALAN RUST Jason 0218",
            "vendor": "Alan Rust",
            "options": [
                "Color",
                "Size"
            ],
            "variants": [
                {
                    "barcode": "0000010002986",
                    "sku": "321107006-025",
                    "options": [
                        "Red",
                        "34\"34"
                    ],
                    "price": 1123.75,
                    "compareAtPrice": 2099.00,
                    "weight": 0,
                    "weightUnit": "GRAMS",
                    "inventoryItem": {
                        "cost": 799.00,
                        "tracked": true
                    },
                    "inventoryManagement": "SHOPIFY",
                    "inventoryQuantities": [
                        {
                            "locationId": "gid://shopify/Location/15778971715",
                            "availableQuantity": 0
                        },
                        {
                            "locationId": "gid://shopify/Location/31110365251",
                            "availableQuantity": 0
                        }
                    ]
                }
            ],
            "metafields": [
                {
                    "value": "73596",
                    "valueType": "STRING",
                    "namespace": "CleverApps",
                    "key": "CleverAppsId"
                }
            ]
        }
    }
}

 

 

1 Like
Highlighted
Shopify Partner
7 0 1

Hi,

Is there any update on this? This causes frustration for our customers as they have to manually enable tracking products or risk having incorrect inventory.

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 170

Hey @Jason_Whetton 

Running your query (after swapping location IDs for my own), I'm seeing tracking enabled for two locations (screenshot).

I'm not sure I'm following - let me know what I'm missing.

 

 

Notice; Out of office, replies will be delayed until my return. Thanks!
0 Likes
Highlighted
Shopify Partner
7 0 1

Hi,

Can you try the create with just one inventory quantity in the list, and then the update with both? This simulates, for example, having added a new location after the product was initally created.

In that case we don't see tracking enabled for the second location in the inventory quantities array.

{
    "query": "mutation productCreate($input: ProductInput!) { productCreate(input: $input) { product { id metafields(first: 1) { edges { node { key value } } } } userErrors { message field } } }",
    "variables": {
        "input": {
            "title": "ALAN RUST Jason 0218",
            "vendor": "Alan Rust",
            "options": [
                "Color",
                "Size"
            ],
            "variants": [
                {
                    "barcode": "0000010002986",
                    "sku": "321107006-025",
                    "options": [
                        "Red",
                        "34\"34"
                    ],
                    "price": 1123.75,
                    "compareAtPrice": 2099.00,
                    "weight": 0,
                    "weightUnit": "GRAMS",
                    "inventoryItem": {
                        "cost": 799.00,
                        "tracked": true
                    },
                    "inventoryManagement": "SHOPIFY",
                    "inventoryQuantities": [
                        {
                            "locationId": "gid://shopify/Location/15778971715",
                            "availableQuantity": 0
                        }
                    ]
                }
            ],
            "metafields": [
                {
                    "value": "73596",
                    "valueType": "STRING",
                    "namespace": "CleverApps",
                    "key": "CleverAppsId"
                }
            ]
        }
    }
}
0 Likes
Highlighted
Shopify Partner
7 0 1

Any solution for this?

I don't see how we can add a new location after going live if we can't enable tracking for all products...

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 170

You can use the inventoryActivate mutation to stock a variant in a new location, here's an example:

mutation inventoryActivate($inventoryItemId: ID!, $locationId: ID!, $available: Int) {
  inventoryActivate(inventoryItemId: $inventoryItemId, locationId: $locationId, available: $available) {
    inventoryLevel {
      id
    }
    userErrors {
      field
      message
    }
  }
}
{
  "available": 10,
  "inventoryItemId": "gid://shopify/ProductVariant/31391931793464",
  "locationId": "gid://shopify/Location/34850111544"
}

 

Notice; Out of office, replies will be delayed until my return. Thanks!
0 Likes
Highlighted
Shopify Partner
7 0 1

Hi,

Thanks that's interesting but I don't think it solves our problem.

We don't keep track of variant ids, since we push the complete product.

We also don't know whether tracking has been previously activated, so wouldn't know when to use the activate mutation.

I would expect that any inventory quantity provided with a variant would automatically activate tracking for the associated location?

0 Likes
Shopify Staff
Shopify Staff
78 8 11

Hey @Jason_Whetton,

Taking a look at a test store with the steps above (productCreate with quantity at one location i.e. the default location for the store, add a new location via the admin, productUpdate with inventoryQuantities for both locations, do not observe Inventory listed in the admin for the second location), inventoryActivate is a necessary step.

As you're likely already aware, Variants have InventoryItems, InventoryItems are tied to Locations through an Inventory Level:

CalD_0-1601589411946.png

Even if you use productUpdate with inventoryQuantities for the second new Location, this doesn't automatically create an InventoryLevel. inventoryActivate creates this object, and the presence of an InventoryLevel on an InventoryItem indicates that this was previously activated.
Here's an example query to see if a product has an InventoryLevel (in the case above, it would return one inventoryLevel before adding a new location, then two after inventoryActivate-ing for the new Location):

{
  product(id: "gid://shopify/Product/5595575058454") {
    title
    description
    variants(first: 1) {
      edges {
        node {
          inventoryItem {
            id
            inventoryLevels(first:8) {
              edges {
                node {
                  id
                  location {
                    id
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

 

Callum | Developer Support @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes