Skip to main content

Sending coupons via CleverTap

In this tutorial, let's set up Talon.One to automatically generate coupons and send them via CleverTap.

Let's imagine you want to email a coupon code to every customer who spends $200 or more on their order.

To do so, we rely on Talon.One's webhook functionality and CleverTap's Upload Events endpoint.

Talon.One requirements

CleverTap requirements

  • You have set up your CleverTap account.
  • You are an Admin user.
  • You have configured an email provider in CleverTap and tested it.

Creating and sending the coupon code

In the sections below, we create a workflow that includes the following steps:

  • Closing a customer session with a cart item value of $200 or more creates a coupon code and triggers a custom webhook in Talon.One.
  • The webhook calls CleverTap's Upload Events endpoint, providing the coupon code and a customer profile ID.
  • Registering the event triggers a campaign in CleverTap.
  • The campaign sends an email with the provided coupon code to the customer with the provided profile ID.

CleverTap workflow

Creating the webhook in Talon.One

To create a webhook that calls CleverTap's Upload Events:

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

  2. In Properties, enter a name and select your Application.

  3. Add the parameters to include in the request. In this tutorial, we'll use the following parameters:

    Param typeParam name
    stringCouponCode
    stringCustomerProfileID
  4. In Request, set Verb to POST.

  5. In URL, enter https://<YOUR_REGION>.api.clevertap.com/1/upload, where YOUR_REGION is your region key, for example, us1.

  6. In Headers, click Add and define the following HTTP headers:

    • X-CleverTap-Account-Id: <YOUR_PROJECT_ID>, where YOUR_PROJECT_ID is your Project ID in CleverTap.
    • X-CleverTap-Passcode: <YOUR_PROJECT_PASSCODE>, where YOUR_PROJECT_PASSCODE is your Passcode in CleverTap.
    • Content-Type: application/json; charset=utf-8
  7. In Payload, add the following request payload:

    {
    "d": [
    {
    "type": "event",
    "evtName": "Coupon Generated",
    "$source": "Talon.One",
    "identity": "${$CustomerProfileID}",
    "evtData": {
    "CouponCode": "${$CouponCode}"
    }
    }
    ]
    }
    note

    To learn more about accessing Talon.One attributes and including them in the webhook, see Using parameters in a webhook.

  8. In Preview, click Copy.

  9. Click Create Webhook.

  10. Paste and run the copied curl command in your terminal.
    This calls the endpoint with placeholder data, which creates a custom event named Coupon Generated in CleverTap. The event is required to create the campaign.

Creating the campaign in CleverTap

To create an email campaign that can be triggered by our webhook:

  1. In CleverTap, in the sidebar, open Campaigns.
  2. Click + Campaign > Email.
  3. In Name, type a name for your campaign.
  4. In Start here > Qualification criteria, select Live behavior and click Done.
  5. In Email Service Provider, select the email provider you configured and click Done.
  6. In Set a goal, click Done.
  7. In Who > Target Segment > As soon as user does, select the name of the event you created (Coupon Generated, in our case) and click Done.
  8. In Control group and target segment cap, click Done.
  9. In What, select Single Message and click Go To Editor.
  10. Select a template and personalize your message in the message editor.
  11. In the email body, type @ and select the desired custom event property (@Coupon Generated - CouponCode, in our case). Replace [default value] with a default value for the coupon code, for example, [DISCOUNT10].
  12. In Sender Details, fill in the sender information as required and click Done.
  13. In When > Date and time, click Done.
  14. In Delivery preferences, click Done.
  15. Click Publish Campaign.

Creating the rule

Now, let's bring it all together by creating a rule in Talon.One that generates the coupon code and triggers the webhook:

WhatNameProperties
Condition 1Check attribute valueSession Total (Current Session) is greater than or equal to 200.
Condition 2Check for event types
and custom event values
Event type is Customer Session Closing.
Effect 1Create coupon code
  • Set your desired coupon settings.
  • Ensure Recipient is set to Current Customer (Friend).
Effect 2Webhooks
  • Choose the name of the webhook you created.
  • Set CouponCode to Generated Coupon in Session.
  • Set ProfileID to Integration ID (Customer Profile).

Testing the setup

Let's test our setup by simulating a purchase with a high cart item value.

  1. Send the following payload to the Update customer session endpoint, where YOUR_PROFILE_ID refers to a customer identity in CleverTap. For testing, provide an email address to send the email to, for example, john@doe.com.

    {
    "customerSession": {
    "profileId": "YOUR_PROFILE_ID",
    "state": "open",
    "cartItems": [
    {
    "name": "Fine woven scarf",
    "sku": "SCARF123",
    "quantity": 1,
    "price": 249.99
    }
    ]
    }
    }
  2. Send the payload again with the state property set to closed.

The session is now closed, with a cart item value greater than $200. This triggers our rule.

The rule calls CleverTap's API endpoint using the webhook, which in turn activates the campaign and sends an email to the provided profile ID.