# Brevo

Brevo (formerly Sendinblue) is an email marketing and CRM platform that helps businesses manage contacts, create and send email campaigns, and track transactional email performance. The Sling Brevo connector extracts data from the Brevo API v3, supporting contacts, contact lists, segments, email campaigns, templates, senders, transactional email reports, and events.

{% 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 Brevo API key

**Inputs:**

* `anchor_date` (optional) -> Starting date for first sync (ISO format, e.g., `2024-01-01`). Defaults to 1 year ago.

### Getting Your API Key

1. Log in to your [Brevo account](https://app.brevo.com/)
2. Click on your name in the top-right corner and select **SMTP & API**
3. Click the **API Keys** tab
4. Click **Generate a new API key**
5. Give your key a name and click **Generate**
6. Copy the API key (it starts with `xkeysib-`)

### Using `sling conns`

{% code overflow="wrap" %}

```bash
sling conns set BREVO type=api spec=brevo secrets='{ api_key: "xkeysib-your-api-key-here" }'
```

{% 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 BREVO='{ type: api, spec: brevo, secrets: { api_key: "xkeysib-your-api-key-here" } }'
```

{% 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:
  BREVO:
    type: api
    spec: brevo
    secrets:
      api_key: "xkeysib-your-api-key-here"
```

## Replication

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

```yaml
source: BREVO
target: MY_POSTGRES

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

streams:
  # Contact management
  contacts:
  contact_lists:
  list_contacts:
  segments:
  contact_attributes:

  # Email campaigns
  email_campaigns:
  email_templates:
  senders:

  # Transactional email analytics
  transactional_reports:
  transactional_events:
```

**Incremental sync example:**

```yaml
source: BREVO
target: MY_POSTGRES

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

streams:
  # These endpoints support incremental sync
  contacts:
  email_campaigns:
  transactional_reports:
  transactional_events:
```

**Full refresh example:**

```yaml
source: BREVO
target: MY_POSTGRES

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

streams:
  # Reference data (best with full-refresh)
  contact_lists:
  list_contacts:
  segments:
  email_templates:
  senders:
  contact_attributes:
```

## Endpoints

### Contact Management

| Endpoint             | Description                                     | Incremental |
| -------------------- | ----------------------------------------------- | ----------- |
| `contacts`           | All contacts with attributes                    | Yes         |
| `contact_lists`      | Contact lists/audiences                         | No          |
| `list_contacts`      | Contacts in each list (child of contact\_lists) | No          |
| `segments`           | Contact segments                                | No          |
| `contact_attributes` | Custom contact attributes/fields                | No          |

### Email Campaigns

| Endpoint          | Description                     | Incremental |
| ----------------- | ------------------------------- | ----------- |
| `email_campaigns` | Email campaigns with statistics | Yes         |
| `email_templates` | SMTP email templates            | No          |
| `senders`         | Verified email senders          | No          |

### Transactional Email Analytics

| Endpoint                | Description                                                 | Incremental |
| ----------------------- | ----------------------------------------------------------- | ----------- |
| `transactional_reports` | Aggregated transactional email reports by day               | Yes         |
| `transactional_events`  | Individual transactional email events (opens, clicks, etc.) | Yes         |

To discover available endpoints:

```bash
sling conns discover BREVO
```

## Parent-Child Endpoints

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

* **list\_contacts** -> Requires `contact_lists` to run first (iterates through each list)

## Incremental Sync

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

* **contacts** - Syncs contacts modified since the last sync via `modifiedSince` filter
* **email\_campaigns** - Syncs campaigns modified since the last sync via `modifiedAt` tracking
* **transactional\_reports** - Syncs reports using date range iteration (30-day windows)
* **transactional\_events** - Syncs events using date range iteration (30-day windows)

### How it works

* **First run:** Fetches all records from the anchor date (defaults to 1 year ago)
* **Subsequent runs:** Only fetches records created or modified after the last sync timestamp

### Custom Anchor Date

You can set a custom starting date for the first sync:

```yaml
connections:
  BREVO:
    type: api
    spec: brevo
    secrets:
      api_key: "xkeysib-your-api-key-here"
    inputs:
      anchor_date: "2024-06-01"
```

## Rate Limiting

The Brevo API enforces rate limits that vary by endpoint and plan. The connector automatically:

* Uses conservative rate limiting (1 request/second)
* Retries with exponential backoff on 429 (rate limit) responses
* Limits concurrency to 2 parallel requests

## Common Use Cases

### Sync Contact and List Data

```yaml
source: BREVO
target: MY_POSTGRES

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

streams:
  contacts:
    mode: incremental
  contact_lists:
  list_contacts:
  segments:
  contact_attributes:
```

### Sync Campaign Performance

```yaml
source: BREVO
target: MY_POSTGRES

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

streams:
  email_campaigns:
  email_templates:
    mode: full-refresh
  senders:
    mode: full-refresh
```

### Sync Transactional Email Analytics

```yaml
source: BREVO
target: MY_POSTGRES

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

streams:
  transactional_reports:
  transactional_events:
```

### Sync All Brevo Data

```yaml
source: BREVO
target: MY_POSTGRES

defaults:
  mode: full-refresh
  object: brevo.{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/brevo.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.
