Applies to: Inventory API | Catalog API
Learn how to use inventory webhooks to receive notifications when quantities are updated for catalog item variations.
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.
Requirements and limitations
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 2xx
response code within 10 seconds of receiving a notification.
Applications that use OAuth must have INVENTORY_READ
permission to subscribe to an inventory event and receive notifications.
How inventory event notifications work
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.count.updated event
An inventory.updated
event is invoked when an inventory count is updated. An inventory count can be updated explicitly in the Square 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
event:
{
"merchant_id": "6SSW7HV8K2ST5",
"type": "inventory.count.updated",
"event_id": "df5f3813-a913-45a1-94e9-fdc3f7d5e3b6",
"created_at": "2020-12-29T18:38:45.455006797Z",
"data": {
"type": "inventory_counts",
"id": "84e4ac73-d605-4dbd-a9e5-ffff794ddb9d",
"object": {
"inventory_counts": [
{
"calculated_at": "2020-12-29T18:38:45.10296Z",
"catalog_object_id": "6F4K33KPNUVDWKZ43KUIFH6K",
"catalog_object_type": "ITEM_VARIATION",
"location_id": "EF6D9SACKWBKZ",
"quantity": "90",
"state": "IN_STOCK"
}
]
}
}
}
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.
Process inventory event 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.
Subscribe to inventory event 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 Console, 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.
- Choose Save.
Note
In the production environment, ignore the Enable Webhooks setting on the Webhooks page. This setting applies to webhooks for Connect V1 APIs (deprecated).
To validate your webhook configuration
You can send a generic notification from the Developer Console 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.
Receive inventory event notifications
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 2xx
response 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.
Property | Description |
---|
merchant_id | The ID of the seller associated with the inventory count. |
location_id | The ID of the seller location where the inventory is stored. |
type | The type of event: inventory.count.updated |
event_id | The unique ID of the inventory event, which is used for idempotency support. For more information, see Idempotency. |
created_at | A timestamp of when the event occurred (for example, 2020-12-28T21:59:15.286Z ). |
data | 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 Square Dashboard
Open the Square Dashboard.
- To test with Sandbox resources, open the Developer Console. Under Sandbox Test Accounts, choose Open for your test account.
- To test with Production resources, open the Square 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.
Note
You can also send a generic test notification from the Developer Console.
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.