# Constant Contact

Constant Contact is an email marketing and digital marketing platform that helps businesses create email campaigns, manage contacts, and track engagement. The Sling Constant Contact connector extracts data from the Constant Contact V3 API, supporting contacts, contact lists, tags, segments, custom fields, email campaigns, and reporting data.

{% 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:**

* `client_id` **(required)** -> Your Constant Contact OAuth2 Application Client ID
* `client_secret` **(required)** -> Your Constant Contact OAuth2 Application Client Secret

**Inputs:**

* `anchor_date` (optional) -> The starting date for historical data extraction (default: 1 year ago). Format: `YYYY-MM-DD`

### Getting Your Credentials

Constant Contact uses **OAuth2 Authorization Code** flow for API authentication:

1. Go to the [Constant Contact Developer Portal](https://developer.constantcontact.com/)
2. Sign in or create a developer account
3. Click **My Applications** > **New Application**
4. Give your app a name (e.g., "Sling Integration")
5. Set the **Redirect URI** to `https://localhost`
6. Select **Authorization Code Flow** and enable **Long Lived Refresh Tokens**
7. Add the following **Scopes**:
   * `contact_data` - Access to contacts, lists, tags, segments, and custom fields
   * `campaign_data` - Access to email campaigns and reporting
   * `account_read` - Access to account information
   * `offline_access` - Required for refresh token support
8. Click **Save** and then **Generate Secret**
9. Copy your **Client ID** (API Key) and **Client Secret**

{% hint style="warning" %}
**Important:** Store your Client Secret securely. It is only shown once when generated.
{% endhint %}

### Using `sling conns`

{% code overflow="wrap" %}

```bash
sling conns set CONSTANT_CONTACT type=api spec=constant-contact secrets='{ client_id: your_client_id, client_secret: your_client_secret }'
```

{% 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 CONSTANT_CONTACT='{ type: api, spec: constant-contact, secrets: { client_id: "your_client_id", client_secret: "your_client_secret" } }'
```

{% 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:
  CONSTANT_CONTACT:
    type: api
    spec: constant-contact
    secrets:
      client_id: "your_client_id"
      client_secret: "your_client_secret"
```

**With anchor date for historical data:**

```yaml
connections:
  CONSTANT_CONTACT:
    type: api
    spec: constant-contact
    secrets:
      client_id: "your_client_id"
      client_secret: "your_client_secret"
    inputs:
      anchor_date: "2020-01-01"
```

## Replication

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

```yaml
source: CONSTANT_CONTACT
target: MY_POSTGRES

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

streams:
  # Core contact data with incremental sync
  contacts:
    mode: incremental

  # Reference data (full-refresh)
  contact_lists:
  contact_tags:
  segments:
  custom_fields:

  # Email campaigns with incremental sync
  email_campaigns:
    mode: incremental

  # Reporting
  email_campaign_summaries:

  # Account info
  account_summary:
```

**Sync all endpoints:**

```yaml
source: CONSTANT_CONTACT
target: MY_POSTGRES

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

streams:
  '*':
```

## Endpoints

### Contacts & Lists

| Endpoint        | Description                                                                           | Incremental |
| --------------- | ------------------------------------------------------------------------------------- | ----------- |
| `contacts`      | Contact records with email, phone, address, custom fields, list memberships, and tags | Yes         |
| `contact_lists` | Contact list definitions with membership counts                                       | No          |
| `contact_tags`  | Tag definitions with contact counts                                                   | No          |
| `segments`      | Saved contact segments                                                                | No          |
| `custom_fields` | Custom field definitions                                                              | No          |

### Email Campaigns

| Endpoint                   | Description                                                   | Incremental |
| -------------------------- | ------------------------------------------------------------- | ----------- |
| `email_campaigns`          | Email campaign metadata (name, status, dates)                 | Yes         |
| `email_campaign_summaries` | Aggregate campaign statistics (sends, opens, clicks, bounces) | No          |

### Account

| Endpoint          | Description                      | Incremental |
| ----------------- | -------------------------------- | ----------- |
| `account_summary` | Account and organization details | No          |

To discover available endpoints:

```bash
sling conns discover CONSTANT_CONTACT
```

## Incremental Sync

The Constant Contact connector supports time-based incremental sync for:

* **contacts** - Uses `updated_after` parameter to fetch only recently modified contacts
* **email\_campaigns** - Uses `after_date` parameter to fetch campaigns created or updated after the last sync

**First run:** Fetches records from `anchor_date` (default: 1 year ago) to present. **Subsequent runs:** Only fetches records modified after the last sync timestamp.

## Rate Limiting

The Constant Contact V3 API has rate limits:

* **10,000 requests per day**
* **4 requests per second**

The connector automatically:

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

## OAuth2 Authorization

On first connection, Sling will open a browser window to authorize the application with Constant Contact. After authorizing, you'll be redirected to `https://localhost` with an authorization code. Sling captures this code and exchanges it for access and refresh tokens automatically.

Tokens are stored locally and refreshed automatically. No manual token management is needed after initial setup.

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).
