Call a webhook
3 minutes read
Advanced
Webhook calls are used to communicate with third-party applications within flows. They allow NGOs to receive and handle incoming messages, delivery receipts and other events from WhatsApp in a seamless and automated manner.
Using Webhooks in Glific
Please have a look at the steps to call Webhooks in Glific.
- Receive the response from a contact in a variable.
- Call Webhook in a node.
- Choose to
Call a webhook
in the dropdown in node action. - Choose
POST
in response type. - Enter the
URL
where you want a Webhook connection. - Click on the
Post Body
tab. - Enter the variables which you want to pass through the webhook.
- Choose to
{
"contact": "@contact",
"results": "@results",
"Emp_name": "Mohit"
"Emp_age": "@results.age.input"
}
- Click
OK
to save the changes
Use webhook response in the flows
- Let's say you make a webhook call (by using the above steps) and you want to use the response variable in the flow.
For example, if you send a response like a below object
{
"success_message" : "You are onboarded.",
"status_code": 200
}
Please note that your webhook should always return a JSON object (not an array).
Then you can use that response as @results.mywebhook.success_message Or if you want to use any other variable then it will be *@results.mywebhook.YOUR_RESPONSE_OBJECT_KEY
Here my webhook is a custom name you defined on your webhook node and success_message is the key of the response object you send back in a webhook call.
Checking Webhook Logs
Once the webhook setup is complete. You can test it by executing the flow in Glific. There may a case, the webhook is not set up correctly and there are some errors in Webhook calls.
Glific has Webhook Logs from where you can check the status of a Webhook call and see if it returned some errors.
- Access
Webhook logs
under theFlows
option from left panel.
- Webhook logs page will show the results of your webhook calls with the below details
Time
- Time of the webhook call.URL
- The URL which is used in webhook call.Status
- Success / ErrorStatus Code
- Status code returned from the webhook call.Error
- Error is an error returned. NULL in the case of successMethod
- GET / POSTRequest Header
- Request header of the webhook callRequest JSON
- JSON of the webhook callResponse JSON
- JSON response received from the webhook call.
- You can click on the data received in the logs to copy or view the full response.
View
will open up the response received in a pop-up window. You can check or copy the text to know more details of the response.