# Create a webhook to Iterable

> In this tutorial, let's use [a webhook][webhook] in Talon.One to trigger an email campaign in Iterable.

> For the complete documentation index, see [llms.txt](https://docs.talon.one/llms.txt).

Let's imagine we want to retrieve an existing coupon code from Talon.One and pass it to Iterable.
The Iterable campaign should then email the coupon code to the target user.

## Talon.One requirements

- You are an [admin](/docs/product/account/account-settings/manage-roles.md#admin-role) user.
- You have set up [an Application][App].
- Your Application contains [a running campaign][campaigns] with the **Coupons** feature
  [enabled](/docs/product/campaigns/settings/manage-campaign-features.md).
- You have [added coupons](/docs/product/campaigns/coupons/create-coupons.md) to the campaign.

You can edit the default format of the coupon codes in
the campaign's <Settings className="icon" /> [**Settings**][coupon format] section.

[coupon format]: /docs/product/campaigns/coupons/coupon-page-overview#edit-coupon-format

## Iterable requirements

- You have set up your Iterable account.
- You have [added users](https://support.iterable.com/hc/en-us/articles/115000770906-Adding-Users-and-Creating-Lists) to your Iterable project.
  Your user data includes the user's first name and a user ID. For this tutorial, we assume the corresponding fields are named `firstName` and `userId`.

## Set up the integration

<StepsContainer>

### Create a triggered campaign in Iterable

To create a campaign that can be triggered from Talon.One, let's first create an email [template](https://support.iterable.com/hc/en-us/articles/205480315-Templates-Overview) in Iterable:

1. In Iterable, open **Content > Templates**.
1. Click **New Template > Email**.
1. Enter a name and click **Create template**.
1. In **Details**, click **Edit details** and enter at least a subject for the email.
1. In **Design**, click **Edit design**. When asked, choose the WYSIWYG editor.
1. Use the following example to create your email template:

   ```jinja2
   Hi {{firstName}},

   Thank you for your recent purchase.

   Use {{couponCode}} to get 10% off your next purchase over $20.

   To unsubscribe from these emails, click {{unsubscribeUrl}}.
   ```

   :::tip
   In the example above, we use double curly braces `{{...}}` for [user profile and event fields](https://support.iterable.com/hc/en-us/articles/205480365-Personalizing-Templates-with-Handlebars#referencing-user-profile-and-event-fields-with-handlebars) and [merge parameters](https://support.iterable.com/hc/en-us/articles/206514205-Universal-Merge-Parameters).

   When the campaign is triggered and the email template is sent, these placeholders are populated with values from Iterable and Talon.One.
   :::

Now, we can create a triggered campaign based on that template. To do so:

1. In Iterable, open **Messaging > Campaigns**.
1. Click **New Campaign > Email**.
1. In **Campaign name**, enter a name.
1. In **Type**, choose **API-Triggered**, and click **Create campaign**.
1. In **Content**, click **Browse templates** and select the template you [created](#create-a-triggered-campaign-in-iterable).
1. Click **Done** to close the template dialog.
1. Click **Review**, **Activate**.The state of the campaign is now **Running**.
1. Make a note of the ID of your campaign.
   

### Create an API key in Iterable

1. Click **Integrations** > **API Keys** > **New API key**.
1. Enter a name and click **Create API key**. Save the key value for later use.

### Create a webhook in Talon.One

Using a [webhook][webhook], we can now trigger the campaign we created. Talon.One provides two kinds of webhooks:

- [Template-based webhooks](#use-a-webhook-template)
- [Custom webhooks](#use-a-custom-webhook)

#### Use a webhook template

For basic integration use cases, Talon.One provides a **Send coupon** webhook template.

When using the template, the webhook payload is pre-populated with data expected by Iterable:
campaign ID, recipient user ID, and coupon code.

To create a webhook based on the Iterable template:

1. Open <Account className="icon" /> **Account** > <Integrations className="icon" /> **Integrations** > **Iterable**.
1. Ensure the **Connection Details** section is up to date with:
   - **Base URL**: The base URL of the Iterable API.
   - **API Key**: The API key you [created](#create-an-api-key-in-iterable).
1. Click **Create Webhook** > **Send coupon**.
1. Enter a name and select the Applications in which the webhook should be available.

After you save the webhook, you can use it to [trigger Iterable emails](#trigger-iterable-emails).

#### Use a custom webhook

For advanced integration use cases, you can create a custom [webhook][webhook] to Iterable:

:::note
For demonstration purposes, the instructions below replicate the **Send coupon** [webhook template](#use-a-webhook-template).
You can use this as a starting point for creating your own custom webhook.
:::

1. In the Campaign Manager, click <Account className="icon"/> **Account** > <Tools className="icon"/>
   **Tools** > **Webhooks** and click **Create Webhook**.
1. Enter a name and select the Applications in which the webhook should be available.
1. Add the parameters to include in the request. In this tutorial, we'll use the following parameters:

   | **Param type** | **Param name**       |
   | -------------- | -------------------- |
   | `number`       | `IterableCampaignID` |
   | `string`       | `CustomerProfileID`  |
   | `string`       | `CouponCode`         |

1. In **Request**, set **Verb** to **POST**.
1. In **URL**, enter `https://api.iterable.com/api/email/target`.
1. In **Headers**, click **Add** and define the following header:
   `Api-Key: YOUR_API_KEY`, where `YOUR_API_KEY` is the API key you [created](#create-an-api-key-in-iterable).
1. In **Payload**, add the request payload. In this tutorial, we'll use the following payload:

   ```json
   {
     "campaignId": ${$IterableCampaignID},
     "recipientUserId": "${$CustomerProfileID}",
     "dataFields": {
       "couponCode": "${$CouponCode}"
     }
   }
   ```

   :::tip
   To learn more about accessing Talon.One attributes and including them in the webhook,
   see [Use parameters in the webhook payload](/docs/product/account/dev-tools/manage-webhooks.md#use-parameters-in-the-webhook-payload).
   :::

After you save the webhook, you can use it to [trigger Iterable emails](#trigger-iterable-emails).

### Trigger Iterable emails

We can now trigger Iterable emails via the Rule Builder. To do so, open your campaign and [create a rule](/docs/product/rules/create-and-manage-rules.md) with the following logic:

- Condition: **Coupon code is valid**
- Effect: In the **Webhooks** section, select the webhook you [created](#create-a-webhook-in-talonone), and make the following settings:
  - In **IterableCampaignId**, type the ID of the Iterable campaign you [created](#create-a-triggered-campaign-in-iterable).
  - In **CouponCode**, select the <Attribute name="Coupon Code (Coupon)" type="builtin" /> attribute.
  - In **CustomerProfileID**, select the <Attribute name="Integration ID (Customer Profile)" type="builtin" /> attribute.

Now, every time the rule is valid, the effect triggers Iterable to send an email with the coupon code to the current customer.

You can trigger the rule, for example, by opening a [customer session](/integration-api#tag/Customer-sessions/operation/updateCustomerSessionV2)
that includes a customer integration ID and a coupon code. If the integration ID matches the `userId` of an existing user in Iterable, an email is sent to that user.

</StepsContainer>

[App]: /docs/product/applications/overview.md
[campaigns]: /docs/product/campaigns/overview.md
[webhook]: /docs/product/account/dev-tools/manage-webhooks.md
