Webhooks provide a way to configure Spare to make requests (JSON though HTTP POST) to your server (or another external service) whenever certain events occur in Spare. A webhook consists of:
- URL - The endpoint where you want Spare to send the event payloads when a matching event happens.
- Topic - The event that triggers the webhook.
- Authorization - A HTTP header that contains a specific secret to ensure that your endpoint is being hit by Spare and not any other malicious source.
There are two parts to getting a webhook to work: creating the webhook and triggering the webhook. After you create a webhook for an event, every time that event occurs, Spare sends a payload request that describes the event to the specified URL. Thus, you can think of webhooks as a kind of notification system.
When to use Webhooks
Use webhooks to integrate applications with Spare, for example:
- Every time a user makes a purchase, you want to notify your Inventory Tracking System to update the available stock within the branch.
- Every time a user enters/leaves the organization, you want to notify your Attendance Tracking System or any other internal system you might be using alongside Spare.
Create webhooks
You can create a webhook through Spare Admin Panel. The administrators are the only ones who can create a webhook. Using the following steps:
- Open the Admin Panel and make sure that you are logged in as an admin.
- Click Settings on the left sidebar, and select Webhooks.
- Click the Plus Icon on the right, enter a Name with a short description.
- Choose a Topic to determine when the webhook will be triggered.
- Enter the URL to the application or server.
- (Optional) Activate the Authorization HTTP Header, and add a secret as a value.
- After you entered all the necessary information for your webhook, click Add.
Secure webhooks
Spare webhooks work by sending an HTTP POST request to the customer service at a particular URL. It's important that you protect your service from potential attacks. As a workaround, you could allowlist the Spare IPs to restrict who can access your webhook resource.