Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Get InventoryItem ID from Product

Solved

Get InventoryItem ID from Product

DoubleShot
Excursionist
12 2 2

Currently I create a new Product with the REST API, and then I make a GraphQL inventoryItemUpdate to change the HS code. However, I need the InventoryItem ID to do this, not the Product ID. How do I get that? Here's my Product creation:

[
    {
        "title": "Test Product",
        "status": "draft",
        "variants": [
            {
                "sku": "testing-sku-234n6j",
                "price": 0,
                "inventory_quantity": 1,
                "inventory_management": "shopify"
            }
        ],
        "body_html": "Test Description",
        "published": true,
        "published_scope": "global"
    }
]
Accepted Solution (1)

Kyle_liu
Shopify Partner
359 46 60

This is an accepted solution.

Hi @DoubleShot 

 

We need to modify your parameter structure. The following are the modified parameters and the return result, which includes variant data information

 

{
    "product": {
        "title": "Test Product",
        "status": "draft",
        "variants": [
            {
                "sku": "testing-sku-234n6j",
                "price": 0,
                "inventory_quantity": 1,
                "inventory_management": "shopify"
            }
        ],
        "body_html": "Test Description",
        "published": true,
        "published_scope": "global"
    }
}

 

 

Response data: 

"inventory_item_id": 51632788603155,

 

{
    "product": {
        "id": 9622172008723,
        "title": "Test Product",
        "body_html": "Test Description",
        "vendor": "devstore11111111",
        "product_type": "",
        "created_at": "2024-07-31T22:13:41-04:00",
        "handle": "test-product-1",
        "updated_at": "2024-07-31T22:13:41-04:00",
        "published_at": null,
        "template_suffix": null,
        "published_scope": "web",
        "tags": "",
        "status": "draft",
        "admin_graphql_api_id": "gid://shopify/Product/9622172008723",
        "variants": [
            {
                "id": 49630311907603,
                "product_id": 9622172008723,
                "title": "Default Title",
                "price": "0.00",
                "position": 1,
                "inventory_policy": "deny",
                "compare_at_price": null,
                "option1": "Default Title",
                "option2": null,
                "option3": null,
                "created_at": "2024-07-31T22:13:41-04:00",
                "updated_at": "2024-07-31T22:13:41-04:00",
                "taxable": true,
                "barcode": null,
                "fulfillment_service": "manual",
                "grams": 0,
                "inventory_management": "shopify",
                "requires_shipping": true,
                "sku": "testing-sku-234n6j",
                "weight": 0.0,
                "weight_unit": "kg",
                "inventory_item_id": 51632788603155,
                "inventory_quantity": 1,
                "old_inventory_quantity": 1,
                "admin_graphql_api_id": "gid://shopify/ProductVariant/49630311907603",
                "image_id": null
            }
        ],
        "options": [
            {
                "id": 12063930089747,
                "product_id": 9622172008723,
                "name": "Title",
                "position": 1,
                "values": [
                    "Default Title"
                ]
            }
        ],
        "images": [],
        "image": null
    }
}

 

 

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me Email Me Buy Me A Coffee

View solution in original post

Replies 4 (4)

Eric-HAN
Shopify Partner
273 30 29

Hi, there 

You need to utilize your product ID to obtain its related product variants, and each product variant has a one-to-one mapping to an InventoryItem.

- Helpful? Please hit Like and mark it as a solution
Want to modify or custom changes on store? Let me help.
- Feel free to Email Me    Buy Me A Coffee
DoubleShot
Excursionist
12 2 2

What API endpoint can I use to do that?

Kyle_liu
Shopify Partner
359 46 60

This is an accepted solution.

Hi @DoubleShot 

 

We need to modify your parameter structure. The following are the modified parameters and the return result, which includes variant data information

 

{
    "product": {
        "title": "Test Product",
        "status": "draft",
        "variants": [
            {
                "sku": "testing-sku-234n6j",
                "price": 0,
                "inventory_quantity": 1,
                "inventory_management": "shopify"
            }
        ],
        "body_html": "Test Description",
        "published": true,
        "published_scope": "global"
    }
}

 

 

Response data: 

"inventory_item_id": 51632788603155,

 

{
    "product": {
        "id": 9622172008723,
        "title": "Test Product",
        "body_html": "Test Description",
        "vendor": "devstore11111111",
        "product_type": "",
        "created_at": "2024-07-31T22:13:41-04:00",
        "handle": "test-product-1",
        "updated_at": "2024-07-31T22:13:41-04:00",
        "published_at": null,
        "template_suffix": null,
        "published_scope": "web",
        "tags": "",
        "status": "draft",
        "admin_graphql_api_id": "gid://shopify/Product/9622172008723",
        "variants": [
            {
                "id": 49630311907603,
                "product_id": 9622172008723,
                "title": "Default Title",
                "price": "0.00",
                "position": 1,
                "inventory_policy": "deny",
                "compare_at_price": null,
                "option1": "Default Title",
                "option2": null,
                "option3": null,
                "created_at": "2024-07-31T22:13:41-04:00",
                "updated_at": "2024-07-31T22:13:41-04:00",
                "taxable": true,
                "barcode": null,
                "fulfillment_service": "manual",
                "grams": 0,
                "inventory_management": "shopify",
                "requires_shipping": true,
                "sku": "testing-sku-234n6j",
                "weight": 0.0,
                "weight_unit": "kg",
                "inventory_item_id": 51632788603155,
                "inventory_quantity": 1,
                "old_inventory_quantity": 1,
                "admin_graphql_api_id": "gid://shopify/ProductVariant/49630311907603",
                "image_id": null
            }
        ],
        "options": [
            {
                "id": 12063930089747,
                "product_id": 9622172008723,
                "name": "Title",
                "position": 1,
                "values": [
                    "Default Title"
                ]
            }
        ],
        "images": [],
        "image": null
    }
}

 

 

If this is helpful, please Like and Accept the solution.
Want to modify or custom changes on store? Let me help.
- Feel free to contact me Email Me Buy Me A Coffee
DoubleShot
Excursionist
12 2 2

I forgot to look under the variants of the return data, thanks for the helpful reply!