Returning "location_id" in "inventory_levels/update" webhook

Hello,

I’m building an app that manages inventory across multiple Shopify locations, and I’m using the inventory_levels/update webhook.

However, I’m struggling to understand how this webhook is intended to work in a multi-location setup.

The docs don’t appear to include a full sample payload, and after removing include_fields, the webhook payload I receive is only:

{
  "inventory_item_id": 46187039785059,
  "available": 2
}

If a product is stocked across multiple locations and the inventory changes at just one location, how am I supposed to determine which location triggered the update?

I was expecting something like a location_id in the payload. Am I missing something in the webhook configuration, or is this simply not included in the inventory_levels/update webhook payload?

Hmm, have you tried not using include_fields and checking what data is returned from the webhook? Because it should return something like:

"body": {
  "inventory_item_id": 271878346596884000,
  "location_id": 24826418,
  "available": null,
  "updated_at": "2021-12-31T19:00:00-05:00",
  "admin_graphql_api_id": "gid://shopify/InventoryLevel/24826418?inventory_item_id=271878346596884015"
},

Hello Luke, I mentioned that I removed the include_fields and it still only returned those two fields.

In my .toml file I have only:

  [[webhooks.subscriptions]]
  uri = "https://.../api/shopify-webhooks/inventory-levels-update"
  topics  = [ "inventory_levels/update" ]

Then in my application I have:

def main(req: func.HttpRequest) -> func.HttpResponse:
    # Read raw body
    raw_body = req.get_body().decode('utf-8')
    logger.warning("Raw Shopify webhook body: %s", raw_body)

which output:

warn: Function.endpoint_inventoryLevelsUpdate.User[0]
      Raw Shopify webhook body: {"inventory_item_id":46187039785059,"available":1}

I assume that this does not result in TOML putting back all fields into the webhook’s definition. Try running this to see how the hook is configured:

sdt webhook ls --shop YOUR_SHOP --access-token YOUR_TOKEN 

And check Fields to see if they’re cleared.

I don’t use TOML (for this and other reasons) but I assume you can explicitly delete it:

sdt webhook rm --shop YOUR_SHOP --access-token YOUR_TOKEN WEBHOOK_ID_OR_TOPIC

Then redeploy and the field restriction will be removed.