Skip to main content

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.

note
  • 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:

  1. Open Webhook.site and, from the Your unique URL section, click Copy to clipboard.

  2. In the Campaign Manager, click Account > Tools > Webhooks > Create Webhook.

  3. In Name, type My webhook test.

  4. In Connected Applications, select the Applications where you want the webhook to be available.

  5. In Request details, set the Verb and URL as follows:

    • Verb: POST
    • URL: Enter the Webhook.site URL you copied in step 1.
  6. In Parameters, add the following parameter:

    • Type: String
    • Name: bodyText
    • Description: The text of the message.
  7. In the Payload section, enter the following payload:

    {
    "customer_integrationId": "${$Profile.IntegrationId}",
    "session_integrationId": "${$Session.IntegrationId}",
    "body": "${$bodyText}"
    }
  8. 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": ""
    }
  9. 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.

  1. Open the Rule Builder in your campaign and create the following rule:

    WhatNameProperties
    ConditionCheck attribute valueSession Total (Current Session) is greater than 200
    ConditionCheck for event types and custom event valuesEvent type: Customer Session Closing
    EffectWebhooks > My webhook testIn bodyText, enter Thank you for your purchase!
  2. 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_URL is the base URL of your Talon.One instance, for example, mycompany.talon.one.
  • YOUR_API_KEY is 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"
}