A webhook (also called a web callback or HTTP push API) is a way for an app to provide other applications with real-time information. A webhook delivers data to other applications as it happens, meaning you get data immediately. Unlike typical APIs where you would need to poll for data very frequently in order to get it real-time. This makes webhooks much more efficient for both provider and consumer. The only drawback to webhooks is the difficulty of initially setting them up.
Webhooks are sometimes referred to as "Reverse APIs," as they give you what amounts to an API spec, and you must design an API for the webhook to use. The webhook will make an HTTP request to your app (typically a POST), and you will then be charged with interpreting it.
When certain events take place on an AlphaTouch system, a Webhook action is triggered. That is to say that the AlphaTouch servers will "PING" a webpage on your server (your Webhook Endpoint) with a POST request that contains a data payload to let your servers know what has happened. The data payload consists of the following fields:
- api_key: The unique API Key for the installation the event took place on.
- action: The action that took place.
- entity: The type of entity that has been impacted by the action.
- entity_id: The ID or array of IDs of the entity or entities impacted by the action.
- data: The data payload which will contain the object (or array of objects) impacted by the action, so you can processs accordingly.
For each Installation that will be integrated with your back-end processes, you will need to specify the Webhook Endpoint in the Installations' API section in the Management Portal.
/* Example "Resident > Update" Payload */
{
"api_key":"UNIQUE_API_KEY",
"action":"update",
"entity":"resident",
"entity_id":17,
"data":{...} /* The Resident object that contains the newly updated data for Resident 17 */
}
/* Example "Resident > Delete" Payload */
{
"api_key":"UNIQUE_API_KEY",
"action":"delete",
"entity":"resident",
"entity_id":17
/* Notice that there is no "data" object as it is not needed for deletion */
}