When a vendor is created or updated in the backend, you might want to update your application to synchronize with the newly created or updated vendor. For example, when a vendor's status is updated, you want to be notified so that you don't attempt in your application to send a purchase order to the vendor if its status has become
INACTIVE. To get your application notified of vendor-created or vendor-updated events, you can use Square API webhooks.
When a vendor is created or updated, a vendor.created or vendor.updated event is sent, respectively, through the Vendors API webhook to applications that have registered to receive the event notification. Your application can parse the received event data and act on the information following your application's business logic.
The following discussion presents a walkthrough to illustrate how to subscribe to the Vendors API webhook events for your application and how to parse the received event data in your application.
In particular, it covers the following tasks:
- Configuring your application to receive the vendor.created or vendor.updated event through the Vendors API webhook.
- Inspecting received
To test receiving the webhook events, follow the instructions in Create Vendors for a Square Seller and Update Vendor Information to have the
vendor.updated events fired, respectively.
To subscribe to the Vendors API event notifications, you must register your application with the Square API webhook through which Square sends notifications to the application. For more information, see Square Webhooks Overview.
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. Choose Sandbox for testing.
Choose Add Endpoint, and then configure the endpoint:
- For Webhook Name, enter a name such as Vendors API 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. To use Webhook.site for testing, copy the Your unique URL on the website and paste it in the URL box.
- Optional. For API Version, choose a Square API version. By default, this is set to the same version as the application.
- For Events, choose vendor.created and vendor.updated. If you want to receive notifications about other events at the same webhook URL, choose them or configure another endpoint.
- Choose Save.
With the webhook configured, you can proceed to test the webhook workflow as follows.
When a new vendor is created, using either the Square API or Seller Dashboard, an instance of the vendor.created event is sent to your application registered for the webhook event.
The following example shows a
vendor.created webhook event received when a vendor is created:
When an existing vendor is updated, an instance of the vendor.updated event is sent to your application.
The following example shows a
vendor.updated event received when the vendor's name is updated from
A Vendor to
Macro Brewing and a note of
Preferred beer supplier is added to the vendor: