Skip to main content

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:

  • 3 attributes: The customer's email and name, and the integration ID of the session.
  • 2 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.

note

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:

  1. Open Webhook.site and, from the Your unique URL section, click Copy to clipboard. Preserve the copied URL for use in step 5.

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

  3. In Properties, enter the webhook's properties.

    • In Webhook title, enter My webhook test.
    • In Applications, select the Applications where you want the webhook to be available.
  4. 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.
    • API key for authentication:
      • In Param type, select string.
      • In Param name, enter APIkey.
      • In Param description, enter The API key.
    tip

    To create a parameter, click Add.

  5. 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}
      note

      We reference the APIkey parameter in the header.

  6. 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 and email properties are referencing custom attributes.
    • Then sessions_integrationId is referencing a built-in attribute.
    • The body property references the bodyText property defined in the webhook.

    How do we know what pattern to use? Read Webhooks.

  7. Click Create.

The webhook is created. Let's use it in a rule.

Creating the rule that uses the webhook

  1. In the Campaign Manager, in a standard campaign, create a rule.

  2. 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 and Event Type = Customer Session Closing.

  3. Click Add effect and select Webhook: My webhook test. Our webhook has two parameters.

    • In bodyText, enter Thank you for your purchase!.
    • In APIkey, enter hf4y283488fbenogiegt307020fkf.
  4. Save the rule and activate the campaign.

    Using a webhook in a rule.

Now, every time a session whose total is greater than $500 gets closed, Webhook.site receives a request containing the following body:

Request payload example
{
"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!"
}