# Run promotions for mParticle audiences

> mParticle allows you to define audiences and connect them to Talon.One to engage with your customers.

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

For example, in mParticle, you can group all customers who recently visited your website into an audience,
and forward the audience to Talon.One.

Then, in Talon.One, you can create coupon codes to offer members of the audience a discount for their next purchase.

:::important
In this tutorial, we assume you are using mParticle's original UI. To enable it, sign in to mParticle and click **Settings** > **Go to Classic Experience**.
:::

## Talon.One requirements

- You are an [admin](/docs/product/account/account-settings/manage-roles.md#admin-role) user.
- You have set up an [Application](/docs/product/applications/create-and-manage-applications.md).
- Your Application contains a running [campaign](/docs/product/campaigns/create-and-manage-campaigns.md) with the **Coupons** feature
  [enabled](/docs/product/campaigns/settings/manage-campaign-features.md).
- You have created an
  [mParticle-specific API key](/docs/product/applications/manage-third-party-api-keys.md).

## mParticle requirements

- You are an [admin](/docs/product/account/account-settings/manage-roles.md#admin-role) user.

## Set up the integration

<StepsContainer>

### Create the feed input

[Feed inputs](https://docs.mparticle.com/guides/get-started/create-an-input/) allow you
to send data to mParticle. In this tutorial, we'll use a custom feed input to add customers to our audience.

:::note
You can also use a [Talon.One feed input](mparticle-enable-integration.md#set-up-a-feed-input) for this.
However, because we're not sending data from Talon.One, a custom feed is more appropriate.
:::

To create the feed input:

1. In mParticle, open **Setup** > **Inputs** and switch to the **Feeds** page.
1. If there's a **Custom Feed** section with existing feeds, open it and click **+**. Otherwise, click **Add Feed Input** and select **Custom Feed**.
1. In the **Input: Feed Configuration** window, configure the following parameters:
   - **Configuration Name**: Type a configuration name.
   - **Feed Status**: Select **Active**.
   - **Input Protection Level**: Select **Create & Update Profiles**.
1. Click **Save**.
1. Save the **Server to Server Key** and **Server to Server Secret** values for later use. We'll need them for [testing](#test-the-connection).

### Create the audience output

[Audience outputs](https://docs.mparticle.com/guides/get-started/connect-an-audience-output/)
allow you to send audience membership data from mParticle to Talon.One. In this tutorial, we'll use an audience output to forward the customer ID of audience members to Talon.One.

To set up the audience output:

1. In mParticle, open **Setup** > **Outputs** and switch to the **Audience** page.
1. If there's a **Talon.One Default** section with existing outputs, open it and click **+**. Otherwise, click **Add Audience Output** and select **Talon.One**.
1. In the **Audience Configuration** window, configure the following parameters:
   - **Configuration Name**: Type a configuration name.
   - **API Key**: Paste the API key you [created](#talonone-requirements).
   - **Deployment URL**: Type the base URL of your Talon.One deployment, for example, `mycompany.europe-west1.talon.one`.
   - **User ID**: Select which attribute to forward to Talon.One as the user ID. For this tutorial, we'll use **Customer ID**.
   - **Run Rule Engine**: Enable this setting.
1. Click **Save**.

### Create the mParticle audience

Now, let's create the audience. It should include all customers who recently visited your website. You can track this via
mParticle's [session events](https://docs.mparticle.com/developers/sdk/web/session-management/).

Customers with at least one active session within the last day should be added to the mParticle
audience, and be forwarded to Talon.One.

To create the mParticle audience:

1. In mParticle, open **Audiences** > **Real-time** and click **New Audience**.
   - In **Audience Name**, type the name of the audience in mParticle.
   - In **External Name**, type the name of the audience that the data should be forwarded to.
   - In **Audience Sources**, select the feed input you [created](#create-the-feed-input).
1. Click **Create**.
1. On the **Build** page, click **Add Criteria**.
1. Click **Sessions**, select the feed input, and click **Done**.
1. In **Recency / Frequency**, enter `Greater Than` `0` `Sessions` `Within the last` `1` `Days` and click **Done**.
1. On the **Connect** page, click **Connect Output**.
1. In the **Connect Output** window, under **Configuration Name**, select the audience output you [created](#create-the-audience-output).
1. Go back to the **Build** page and click **Activate**.

An audience with the external name is automatically created in Talon.One. Customers
who join the mParticle audience will be forwarded to the Talon.One audience.

### Build the rule in Talon.One

To reference the audience in your Talon.One [campaign](/docs/product/campaigns/overview.md), create a rule with the following logic:

- Condition: **Has joined an audience**, with the audience created by mParticle selected.
- Effect: **Create coupon code**.

When a customer profile is added to the audience via the mParticle connection,
the rule is triggered, and a coupon code is created.

</StepsContainer>

## Test the connection

Let's test our setup using the [Events API](https://docs.mparticle.com/developers/apis/http/) provided by mParticle.

To test the connection:

1. Use curl or a similar tool to send the following request, where:
   - `FEED_INPUT_KEY` and `FEED_INPUT_SECRET` are the key and secret values of the feed input you [created](#create-the-feed-input).
   - `YOUR_CUSTOMER_ID` is a customer ID of your choice, for example, `John Doe`.

   ```js
   curl --location 'https://s2s.mparticle.com/v2/events' --user 'FEED_INPUT_KEY:FEED_INPUT_SECRET' --header 'Content-Type: application/json' --data '{
     "schema_version": 2,
     "environment": "development",
     "user_identities": {
       "customer_id": "YOUR_CUSTOMER_ID"
     },
     "events": [
       {
         "data": {},
         "event_type": "session_start"
       }
     ]
   }'
   ```

   :::note
   This request is for testing purposes only. You should [customize it for your actual setup](https://docs.mparticle.com/developers/apis/http/#upload-event-data).
   :::

1. In mParticle, open **Data Master** > **Live Stream** and check whether mParticle has received the request.
1. In Talon.One:
   1. Click <Audiences className="icon" /> **Audiences**, open the audience created by mParticle, and check whether a customer with the given customer ID has been added to the audience.

      :::note
      Adding members to the audience may take a few minutes.
      :::

   1. Open your campaign, click <Coupons className="icon"/> **Coupons**, and check whether a coupon has been generated for the given customer ID.
