Handle Inventory Event Notifications
The Inventory API exposes a webhook to dispatch
inventory.count.updated events every time an inventory quantity is updated for a catalog item variation.
Your application can subscribe to the webhook to receive
inventory.count.updated event notifications to track inventory for item variations and changes in near real time reliably and accurately.
Each inventory event notification includes basic information, such as the event type and event ID. The
data field of each webhook notification contains detailed information about the specific event.
inventory.updated event is invoked when an inventory count is updated. An inventory count can be updated explicitly in the Seller Dashboard or using the Square Inventory API BatchChangeInventory endpoint. It can also be updated automatically when an order is placed and paid for.
The following shows an example of the
inventory.count.updated webhook event also sends notifications when an item variation stock changes state. For state adjustments,
inventory.count.updated sends a single notification containing two inventory counts: one count that describes the quantity and state before the state change and one that describes the quantity and state after the state change.
A single webhook notification can contain up to 100 inventory counts. If a bulk update includes more than 100 updates, the event data spans multiple webhook notifications.
To process inventory event notifications, you need to perform the following tasks:
Meet requirements and understand limitations.
Subscribe to inventory event notifications.
Handle received event notifications.
Test and deploy your application.
The following sections describe each of these tasks. For information about general webhooks requirements, components, and processes, see Square Webhooks Overview.
The following requirements and limitations apply to webhooks for inventory events:
Your notification URL must be a publicly available HTTPS URL. It must also return an
HTTP 2xxresponse code within 10 seconds of receiving a notification.
Applications that use OAuth must have
INVENTORY_READpermission to subscribe to an inventory event and receive notifications.
To subscribe to inventory event notifications, you can configure webhooks for your Square inventory application. A webhook registers the URL that Square should send notifications to, the events you want to be notified about, and the Square API version.
To configure a webhook
In the Developer Dashboard, open the application to which you want to subscribe.
In the left pane, choose Webhooks.
At the top of the page, choose Sandbox or Production. Use the Sandbox environment for testing.
Choose Add Endpoint, and then configure the endpoint:
For Webhook Name, enter a name such as Inventory Webhook.
For URL, enter your notification URL. If you don't have a working URL yet, you can enter https://example.com as a placeholder.
Optional. For API Version, choose a Square API version. By default, this is set to the same version as the application.
For Events, choose inventory.count.updated. If you want to receive notifications about other events at the same webhook URL, choose them or configure another endpoint.
In the production environment, ignore the Enable Webhooks setting on the Webhooks page. This setting applies to webhooks for Connect V1 APIs (deprecated).
You can send a generic notification from the Developer Dashboard to validate that your webhook is configured correctly.
On the Webhooks page for your application, choose the webhook that you want to test.
In the Endpoint Details pane, choose More, and then choose Send Test Event.
Select an event and then choose Send. If the endpoint is configured correctly, the Send Test Event window displays the response code and notification body.
To handle notifications, applications typically perform the following steps:
Validate the authenticity of the notification. For more information, see Verify and Validate an Event Notification.
Respond with an
HTTP 2xxresponse code within 10 seconds of receiving the notification.
Inspect, process, store, or forward the notification.
The body of the notification is a JSON object that contains the following properties.
|The ID of the seller associated with the inventory count.|
|The ID of the seller location where the inventory is stored.|
|The type of event: |
|The unique ID of the inventory event, which is used for idempotency support. For more information, see Idempotency.|
|A timestamp of when the event occurred (for example, |
|Information about the inventory count change, represented by the InventoryCountUpdatedSquareEventData object.|
To test your webhook with actual resources, change an inventory quantity of an item variation in your account. Make sure to test with the same environment (Sandbox or Production) where you registered for the webhook.
The following are some ways you can trigger inventory event notifications.
Test from the Seller Dashboard
Open the Seller Dashboard.
In the left pane, choose Items, select an item to open the Edit Item sheet, choose stock, turn on tracking if it's not already on, select an adjustment reason, and then update the stock count.
Test from API Explorer
Sign in to API Explorer and choose your Sandbox or Production environment. Call the Inventory API BatchChangeInventory endpoint as needed to test your webhook.
Test using cURL
Send cURL requests to the Inventory API endpoint. For more information, see Build and Manage a Simple Inventory.
You can also send a generic test notification from the Developer Dashboard.
You should receive notifications for inventory events that you subscribe to. Square doesn't send notifications for events that fail.
For information about troubleshooting Square webhooks, see Troubleshoot Webhooks.