Get InventoryItem ID from Product

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"
    }
]

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.

What API endpoint can I use to do that?

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
    }
}

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