Creating webhooks
Let's create a webhook in the Campaign Manager to send some data from Talon.One. The objective is to simulate how we can trigger an email sent by an external platform.
Let's use Webhook.site as recipient of our webhook. Webhook.site allows us to inspect the content of our webhook.
We want to send the following data:
- Three attributes: The customer's email and name, and the integration ID of the session.
- Two parameters: The body text of the email and the API key for authentication.
We recommend that you read the generic explanation about what attributes and parameters are in webhooks before following this tutorial.
If you prefer sending the data from Talon.One as an effect, create a custom effect instead.
Creating the webhook
Let's create our webhook:
-
Open Webhook.site and, from the Your unique URL section, click Copy to clipboard. Preserve the copied URL for use in step 5.
-
In the Campaign Manager, click Account > Tools > Webhooks > Create Webhook.
-
In Properties, enter the webhook's properties.
- In Name, enter
My webhook test
. - (Optional) In Description, type a description for the webhook.
- In Applications, select the Applications where you want the webhook to be available.
- In Name, enter
-
In Parameters, we create two parameters for the request.
- Body text of the email:
- In Param type, select
string
. - In Param name, enter
bodyText
. - In Param description, enter
The body of the email
.
- In Param type, select
- API key for authentication:
- In Param type, select
string
. - In Param name, enter
APIkey
. - In Param description, enter
The API key
.
- In Param type, select
tipTo create a parameter, click Add.
- Body text of the email:
-
In Request, define the Verb and URL as follows:
- Verb:
POST
- URL: the Webhook.site URL you copied in step 1.
- Header:
Content-Type: application/json
- Header:
Authorization: ApiKey-v1 ${$APIkey}
noteWe reference the
APIkey
parameter in the header.
- Verb:
-
In Request payload, add the following payload:
Request payload{
"name": "${$Profile.Attributes.Name}",
"email": "${$Profile.Attributes.Email}",
"session_integrationId": "${$Session.IntegrationId}",
"body": "${$bodyText}"
}important-
The
name
andemail
properties are referencing custom attributes. -
Then
sessions_integrationId
is referencing a built-in attribute. -
The
body
property references thebodyText
property defined in the webhook.
How do we know what pattern to use? Read Webhooks.
-
-
Click Create.
The webhook is created. Let's use it in a rule.
Creating the rule that uses the webhook
-
In the Campaign Manager, in a standard campaign, create a rule.
-
Choose a condition.
In our case, we can imagine we want to trigger an email when the customer spends $500. We can use
Session total > 500
andEvent Type = Customer Session Closing
. -
Click Add effect and select Webhook: My webhook test. Our webhook has two parameters.
- In
bodyText
, enterThank you for your purchase!
. - In
APIkey
, enterhf4y283488fbenogiegt307020fkf
.
- In
-
Save the rule and activate the campaign.
Now, every time a session whose total is greater than $500 gets closed, Webhook.site receives a request containing the following body:
{
"name": "<name of the customer>",
"email": "<email address of the customer>",
"session_integrationId": "<the session id set from the integration layer>",
"body": "Thank you for your purchase!"
}