Tracking inventory items

Highlighted
Shopify Partner
4 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
1028 137 160

Hey @Jason_Whetton,

 

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

0 Likes
Highlighted
Shopify Partner
4 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
4 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
1028 137 160

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.

 

 

0 Likes
Highlighted
Shopify Partner
4 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