# Mailchimp

Mailchimp is an email marketing platform that helps businesses manage subscriber lists, create and send campaigns, and analyze email marketing performance. The Sling Mailchimp connector extracts data from the Mailchimp Marketing API, supporting audiences, campaigns, automations, member data, segments, and analytics.

{% hint style="success" %}
**CLI Pro Required**: APIs require a [CLI Pro token](https://docs.slingdata.io/sling-cli/cli-pro) or [Platform Plan](https://docs.slingdata.io/sling-platform/platform).
{% endhint %}

## Setup

The following credentials and inputs are accepted:

**Secrets:**

* `api_key` **(required)** -> Your Mailchimp API key

**Inputs:**

* `server_prefix` **(required)** -> Your Mailchimp datacenter server prefix (e.g., `us4`, `us5`, `us6`, `us13`, etc.)

### Getting Your API Key

1. Log in to your [Mailchimp account](https://login.mailchimp.com/)
2. Click on your profile icon in the bottom left corner
3. Select **Account** or go to **Account > Extras > API keys**
4. Scroll down to the **Your API Keys** section
5. Click **Create A Key** to generate a new API key
6. Copy the API key (it looks like: `abc123def456abc123def456abc123def456ab12-us4`)

The API key itself contains your server prefix. For example:

* `abc123-us4` means your server prefix is `us4`
* `abc123-us13` means your server prefix is `us13`

### Using `sling conns`

{% code overflow="wrap" %}

```bash
sling conns set MAILCHIMP type=api spec=mailchimp secrets='{ api_key: "abc123def456abc123def456abc123def456ab12-us4" }' inputs='{ server_prefix: "us4" }'
```

{% endcode %}

### Environment Variable

See [here](https://docs.slingdata.io/sling-cli/environment#dot-env-file-.env.sling) to learn more about the `.env.sling` file.

{% code overflow="wrap" %}

```bash
export MAILCHIMP='{ type: api, spec: mailchimp, secrets: { api_key: "abc123def456abc123def456abc123def456ab12-us4" }, inputs: { server_prefix: "us4" } }'
```

{% endcode %}

### Sling Env File YAML

See [here](https://docs.slingdata.io/sling-cli/environment#sling-env-file-env.yaml) to learn more about the sling `env.yaml` file.

```yaml
connections:
  MAILCHIMP:
    type: api
    spec: mailchimp
    secrets:
      api_key: "abc123def456abc123def456abc123def456ab12-us4"
    inputs:
      server_prefix: "us4"
```

## Replication

Here's an example replication configuration to sync Mailchimp data to a PostgreSQL database:

```yaml
source: MAILCHIMP
target: MY_POSTGRES

defaults:
  mode: incremental
  object: mailchimp.{stream_name}

streams:
  # Core audience data
  lists:
  list_members:
  segments:
  segment_members:

  # Campaign data
  campaigns:
  unsubscribes:
  email_activity:

  # Automation and segmentation
  automations:
  interest_categories:
  interests:

  # Analytics
  reports:
  tags:
```

**Incremental sync example:**

```yaml
source: MAILCHIMP
target: MY_POSTGRES

defaults:
  mode: incremental
  object: mailchimp.{stream_name}

streams:
  # These endpoints support incremental sync
  campaigns:
  list_members:
  segments:
  reports:
```

**Full refresh example:**

```yaml
source: MAILCHIMP
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: mailchimp.{stream_name}

streams:
  # Reference data (best with full-refresh)
  lists:
  interest_categories:
  interests:
  tags:
```

## Endpoints

### Audience Management

| Endpoint              | Description                                                 | Incremental |
| --------------------- | ----------------------------------------------------------- | ----------- |
| `lists`               | Email lists/audiences                                       | No          |
| `list_members`        | Members in each audience                                    | Yes         |
| `segments`            | Audience segments                                           | Yes         |
| `segment_members`     | Members in each segment (child of segments)                 | No          |
| `interest_categories` | Interest categories in audiences (child of lists)           | No          |
| `interests`           | Interests within categories (child of interest\_categories) | No          |
| `tags`                | Tags applied to audiences (child of lists)                  | No          |

### Campaign Management

| Endpoint         | Description                                                             | Incremental |
| ---------------- | ----------------------------------------------------------------------- | ----------- |
| `campaigns`      | Email campaigns                                                         | Yes         |
| `unsubscribes`   | Unsubscribe events from campaigns (child of campaigns)                  | No          |
| `email_activity` | Email activity (opens, clicks, etc.) for campaigns (child of campaigns) | No          |

### Automation

| Endpoint      | Description          | Incremental |
| ------------- | -------------------- | ----------- |
| `automations` | Automation workflows | No          |

### Analytics

| Endpoint  | Description                  | Incremental |
| --------- | ---------------------------- | ----------- |
| `reports` | Campaign performance reports | Yes         |

To discover available endpoints:

```bash
sling conns discover MAILCHIMP
```

## Parent-Child Endpoints

Some endpoints are children of parent endpoints and require the parent to run first:

* **list\_members** -> Requires `lists` to run first (iterates through each list)
* **segments** -> Requires `lists` to run first
* **segment\_members** -> Requires `segments` to run first
* **interest\_categories** -> Requires `lists` to run first
* **interests** -> Requires `interest_categories` to run first
* **tags** -> Requires `lists` to run first
* **unsubscribes** -> Requires `campaigns` to run first
* **email\_activity** -> Requires `campaigns` to run first

## Incremental Sync

The Mailchimp connector supports time-based incremental sync for the following endpoints:

* **campaigns** - Syncs new campaigns by `create_time`
* **list\_members** - Syncs new/modified members by `last_changed`
* **segments** - Syncs new/modified segments by `updated_at`
* **reports** - Syncs new campaign reports by `send_time`

### How it works

* **First run:** Fetches all records from the beginning
* **Subsequent runs:** Only fetches records created or modified after the last sync timestamp

## Rate Limiting

The Mailchimp API has rate limits that vary by account type:

* **Free/Standard:** 10 requests/second
* **Premium:** 10 requests/second

The connector automatically:

* Uses conservative rate limiting (5 requests/second)
* Retries with exponential backoff on 429 (rate limit) responses

## Common Use Cases

### Sync Campaign Performance Analytics

```yaml
source: MAILCHIMP
target: MY_POSTGRES

defaults:
  mode: incremental
  object: campaigns.{stream_name}

streams:
  campaigns:
  reports:
  email_activity:
  unsubscribes:
```

### Sync Audience and Subscriber Data

```yaml
source: MAILCHIMP
target: MY_POSTGRES

defaults:
  mode: incremental
  object: audiences.{stream_name}

streams:
  lists:
  list_members:
  segments:
  segment_members:
```

### Sync Audience Structure and Configuration

```yaml
source: MAILCHIMP
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: audience_config.{stream_name}

streams:
  lists:
  interest_categories:
  interests:
  tags:
```

### Sync All Mailchimp Data

```yaml
source: MAILCHIMP
target: MY_POSTGRES

defaults:
  mode: incremental
  object: mailchimp.{stream_name}

streams:
  # Sync all available endpoints
  '*':
```

If you are facing issues connecting, please reach out to us at <support@slingdata.io>, on [discord](https://discord.gg/q5xtaSNDvp) or open a Github Issue [here](https://github.com/slingdata-io/sling-cli/issues).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.slingdata.io/connections/api-connections/mailchimp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
