06.18-Starting a Webhook
Although the platform provides flexibles methods to storage and evaluates values, you can have the necessity to get data from an external application...
Written by
Updated August 3, 2021
Although the platform provides flexibles methods to storage and evaluates values, you can have the necessity to get data from an external application (using a coupon code, order number or patient ID) and evaluate it using the flow logic; or sending information (collected through a ruleset flow and attributed to variables) to a external application. This can be acquired through a webhook call for your flow. When a user reaches a webhook, let’s call the URL that you configured, passing the text message sent from your contact, as all collected variables until that flow step. If return JSON, the ilhapush will save these values to use them in the future.
For example, if you configure a webhook on the beginning of your flow to look for an order, it will return JSON keys on your site and the values in a format similar to the following:
{ “status”: “Shipped”, “number”: “CU001”, “name”: “Ben Haggerty”, “ship_date”: “October 9th”, “delivery_date”: “April 3rd”, “description”: “Vogue White Wall x 4” } You will be able to make references to this key in any step on the flow through the variable @extra, for example, @Extra.status.
On this example, we can show how to configure a flow to look for a request and conduct the contact comparing with results. You can go on with the flow “Order Status Checker” located on the flows guide into your account.
Attribute responses from your contacts in a flow variable.
Create a RuleSet that collects the value-target from your contacts and saves as a flow variable. On the example below, we are creating a Wait for Response RuleSet that will collect the requests numbers from our contacts and save them as a flow variable @flow.pedido:
Look for external data
Create a webhook call, alter the “POST” request, and type a URL containing the JSON keys that you want to call:
The JSON coincides with an order number presented by your contacts using the flow variable @flow.request that will be saved to “webhook request” @flow.order_webhook. The action registers into the simulator will show them that the values are being developed.
Evaluate an External Variable
After that, we should a slip for RuleSet that evaluates one of the returned values against the response. On the example below the status key @extra.status only contains one of the three values (Shipped, Pending, Cancelled), we can use the Has All These Words to discern which value will return to the contact.
If the status value returned is the same as the “Send”, “pending” or “canceled”, the contact will follow in conformity. On the contrary, the contact will pass through the “others” category and receive an order to resend a @flow.status value:
Visualizing Webhook Logs
To visualize the webhook logs, go to the account page, click on the webhook icon, after that, click on the “API Register” on the bottom right:
In your recent events will be listed in the chronological order with the type of event, status, channel, and attempts.
You can click on the event to see the order content and the JSON proprieties correspondents.