Create a webhook
Let's create a webhook in the Campaign Manager to send a message from Talon.One.
We will use Webhook.site as the recipient of our webhook, which allows us to inspect the webhook's content.
We want to send the following data:
- Two attributes: The customer integration ID and the session integration ID.
- One parameter: The body text of the message.
We highly recommend that you read about webhooks and defining their payload before following this tutorial.
- If you prefer sending the data from Talon.One as an effect, create a custom effect instead.
- To create and manage webhooks, ensure you are the admin or Application admin for every Application the webhook is connected to.
Create the webhook
Let's create our webhook:
-
Open Webhook.site and, from the Your unique URL section, click Copy to clipboard.
-
In the Campaign Manager, click Account > Tools > Webhooks > Create Webhook.
-
In Name, type
My webhook test. -
In Connected Applications, select the Applications where you want the webhook to be available.
-
In Request details, set the Verb and URL as follows:
- Verb: POST
- URL: Enter the Webhook.site URL you copied in step 1.
-
In Parameters, add the following parameter:
- Type: String
- Name:
bodyText - Description:
The text of the message.
-
In the Payload section, enter the following payload:
{
"customer_integrationId": "${$Profile.IntegrationId}",
"session_integrationId": "${$Session.IntegrationId}",
"body": "${$bodyText}"
} -
In the Test section, click Test Webhook.
Talon.One sends a test request to Webhook.site, which should look like this:{
"body": "",
"customer_integrationId": "",
"session_integrationId": ""
} -
Click Create Webhook.
Create the rule that uses the webhook
In a standard campaign, let's create a rule that triggers the webhook when a customer purchases products worth more than $200.
-
Open the Rule Builder in your campaign and create the following rule:
What Name Properties Condition Check attribute value Session Total (Current Session) is greater than 200Condition Check for event types and custom event values Event type: Customer Session ClosingEffect Webhooks > My webhook test In bodyText, enter Thank you for your purchase! -
Save the rule and activate the campaign.
Trigger the rule
Let's test our setup by simulating a purchase with a high cart item value.
Use curl or a similar tool to send the following request, where:
YOUR_BASE_URLis the base URL of your Talon.One instance, for example,mycompany.talon.one.YOUR_API_KEYis a valid Integration API key for your campaign.
curl -X PUT 'https://YOUR_BASE_URL/v2/customer_sessions/session_12345' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: ApiKey-v1 YOUR_API_KEY' \
--data '{
"customerSession": {
"state": "closed",
"profileId": "customer_12345",
"cartItems": [
{
"name": "Fine woven scarf",
"sku": "SCARF123",
"quantity": 1,
"price": 249.99
}
]
}
}'
Sending this request creates a session with a cart item value greater than $200 and immediately closes it. This triggers our rule, which in turn calls our webhook.
On Webhook.site, you should see a new request with the following content:
{
"body": "Thank you for your purchase!",
"customer_integrationId": "customer_12345",
"session_integrationId": "session_12345"
}