> ## Documentation Index
> Fetch the complete documentation index at: https://kb.aampe.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Salesforce Marketing Cloud (SFMC)

> Estimated setup time: 30 minutes

## Requirements

**All channels**

* `client_id`
* `client_secret`
* Instance subdomain (e.g. `mc563885gzs27c5t9-63k636ttgm`)

**Email channel (additional)**

* `definition_key` — created during email setup below

Aampe calls the [SFMC](https://developer.salesforce.com/docs/marketing/marketing-cloud/guide/integration-s2s-client-credentials.html) server-to-server REST API on your behalf using OAuth 2.0 client credentials. Tokens are fetched and cached automatically — you only need to supply the client ID and secret.

<Note>
  The access token SFMC issues expires after 20 minutes. Aampe handles token refresh automatically — do not share access tokens directly.
</Note>

***

## Step 1 — Create an Installed Package

1. Log in to SFMC and open **Setup** (gear icon, top right).
2. Under **Platform Tools**, expand **Apps** and select **Installed Packages**.
3. Click **New** and name the package `aampe-integration`.
4. Under **Components**, click **Add Component** and select **API Integration**.
5. Select **Server-to-Server** as the integration type.
6. Grant the following permissions:

| Scope       | Permission           | Required for                       |
| ----------- | -------------------- | ---------------------------------- |
| Email       | Read, Write, Send    | Email sends                        |
| Push        | Read, Write, Send    | Push sends                         |
| Channels    | Read, Write          | Channel access                     |
| Automations | Read, Write, Execute | Tracking Extract jobs (email only) |

7. Click **Save**.
8. Copy the **Client ID**, **Client Secret**, and **REST Base URI** from the package summary page. These are the credentials you will enter in Aampe.

Your REST Base URI will be in the format `https://YOUR_SUBDOMAIN.rest.marketingcloudapis.com` — only the subdomain portion is required.

***

## Step 2 — Push channel setup

No additional SFMC configuration is required beyond the Installed Package above. Enter the following into your Aampe integration settings:

* `client_id`
* `client_secret`
* `subdomain`
* `message_id` — the SFMC push message ID Aampe should send against

***

## Step 3 — Email channel setup

Email requires three one-time setup steps in SFMC.

### 3a — Create the shell template in Content Builder

Aampe generates the full HTML email body per user and passes it at send time. The Content Builder template acts as a thin delivery wrapper — Aampe owns all content and styling.

1. In SFMC, go to **Content Builder** and click **Create** > **Email** > **HTML Paste**.
2. Name it `aampe-email-shell`.
3. Set the subject line to:
   ```
   %%=AttributeValue("subject")=%%
   ```
4. Set the body to:
   ```html theme={null}
   <!DOCTYPE html>
   <html>
   <head></head>
   <body>
   %%=TreatAsContent(AttributeValue("msg_body"))=%%
   <!-- Add your standard unsubscribe footer here -->
   </body>
   </html>
   ```
5. Replace the comment with your organisation's unsubscribe footer. The built-in SFMC profile centre link can be used:
   ```
   <a href="%%profile_center_url%%" alias="Unsubscribe">Unsubscribe</a>
   ```
6. Save the template.

<Note>
  `TreatAsContent()` evaluates the passed HTML as live content. Aampe automatically escapes `%%` sequences in message bodies to prevent unintended AMPscript evaluation.
</Note>

### 3b — Create a send definition

1. Create a send definition referencing the shell template from step 3a. See [createSendDefinition](https://developer.salesforce.com/docs/marketing/marketing-cloud/references/mc_rest_transactional_messaging_email/createSendDefinition.html).
2. Ensure `options.tracking` has `opens` and `clicks` set to `true` — these are required for Aampe's reward signal.
3. Copy the **Definition Key** and enter it into your Aampe integration settings.

<Note>
  One send definition is sufficient for all Aampe email sends — you do not need one per campaign or segment.
</Note>

### 3c — Configure Tracking Extracts for event data

Aampe reads delivery events (sent, opens, clicks, bounces, unsubscribes) via daily Automation Studio Tracking Extracts.

1. In **Automation Studio**, create a new Automation.
2. Add a **Tracking Extract** activity for each event type: Sent, Opens, Clicks, Bounces, Unsubscribes.
3. Set the output destination to S3 or SFTP.
4. Schedule the automation to run daily.

The `messageKey` field in the extract output is the join key between SFMC tracking rows and Aampe send records — ensure it is included in the extract schema. See [Tracking Extract reference](https://help.salesforce.com/s/articleView?id=sf.mc_as_tracking_extract.htm\&type=5).

***

**You are all set with SFMC!**
