Skip to main content

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.

  1. Receive the response from a contact in a variable.

image

  1. Call Webhook in a node.
    1. Choose to Call a webhook in the dropdown in node action.
    2. Choose POST in response type.
    3. Enter the URL where you want a Webhook connection.
    4. Click on the Post Body tab.
    5. Enter the variables which you want to pass through the webhook.
{
"contact": "@contact",
"results": "@results",
"Emp_name": "Mohit"
"Emp_age": "@results.age.input"
}

image

image

  1. Click OK to save the changes

Use webhook response in the flows

  1. Let's say you make a webhook call (by using the above steps) and you want to use the response variable in the flow.

image

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

image

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.

  1. Access Webhook logs under the Flows option from left panel.
Screenshot 2024-03-06 at 3 13 42 PM
  1. Webhook logs page will show the results of your webhook calls with the below details
    1. Time - Time of the webhook call.
    2. URL - The URL which is used in webhook call.
    3. Status - Success / Error
    4. Status Code- Status code returned from the webhook call.
    5. Error - Error is an error returned. NULL in the case of success
    6. Method - GET / POST
    7. Request Header - Request header of the webhook call
    8. Request JSON - JSON of the webhook call
    9. Response JSON - JSON response received from the webhook call.
Screenshot 2024-03-06 at 3 12 51 PM
  1. You can click on the data received in the logs to copy or view the full response.

image

  1. 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.

image


Reference Article