# Chargebee

Chargebee is a subscription billing and revenue management platform that helps businesses automate recurring billing, manage subscriptions, and handle invoicing. The Sling Chargebee connector extracts data from the Chargebee REST API, supporting customers, subscriptions, invoices, transactions, orders, and more.

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

## Setup

The following credentials and inputs are accepted:

**Secrets:**

* `api_key` **(required)** -> Your Chargebee full-access API key
* `site` **(required)** -> Your Chargebee site subdomain (e.g., if your Chargebee URL is `https://mycompany.chargebee.com`, the site is `mycompany`)

**Inputs:**

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

### Getting Your API Key

1. Log in to your [Chargebee Dashboard](https://app.chargebee.com/)
2. Go to **Settings** > **Configure Chargebee** > **API Keys**
3. Click **Add API Key** and select **Full-Access Key**
4. Copy the generated API key

{% hint style="warning" %}
**Important:** Use a Full-Access API key for read access to all resources. Read-Only keys may not have access to all endpoints.
{% endhint %}

### Using `sling conns`

Here are examples of setting a connection named `CHARGEBEE`. We must provide the `type=api` property:

{% code overflow="wrap" %}

```bash
sling conns set CHARGEBEE type=api spec=chargebee secrets='{ api_key: your_full_access_api_key, site: your-site-subdomain }'
```

{% endcode %}

### Environment Variable

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

{% code overflow="wrap" %}

```bash
export CHARGEBEE='{ type: api, spec: chargebee, secrets: { api_key: "your_full_access_api_key", site: "your-site-subdomain" } }'
```

{% endcode %}

### Sling Env File YAML

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

```yaml
connections:
  CHARGEBEE:
    type: api
    spec: chargebee
    secrets:
      api_key: "your_full_access_api_key"
      site: "your-site-subdomain"
```

**With anchor date for historical data:**

```yaml
connections:
  CHARGEBEE:
    type: api
    spec: chargebee
    secrets:
      api_key: "your_full_access_api_key"
      site: "your-site-subdomain"
    inputs:
      anchor_date: "2024-01-01"
```

## Replication

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

```yaml
source: CHARGEBEE
target: MY_POSTGRES

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

streams:
  # sync all endpoints
  '*':

  # Exclude endpoints if not needed
  site_migration_detail:
    disabled: true
```

**Full refresh example for reference data:**

```yaml
source: CHARGEBEE
target: MY_POSTGRES

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

streams:
  # Reference data (no incremental support)
  coupon:
  item_family:
  comment:
  gift:
  promotional_credit:
  unbilled_charge:
```

## Endpoints

### Customers & Subscriptions

| Endpoint         | Description                       | Incremental |
| ---------------- | --------------------------------- | ----------- |
| `customer`       | Customer records                  | Yes         |
| `subscription`   | Active and canceled subscriptions | Yes         |
| `payment_source` | Saved payment sources             | Yes         |

### Billing & Invoicing

| Endpoint          | Description                      | Incremental |
| ----------------- | -------------------------------- | ----------- |
| `invoice`         | Invoices with line items         | Yes         |
| `credit_note`     | Credit notes                     | Yes         |
| `transaction`     | Payment transactions             | Yes         |
| `unbilled_charge` | Pending charges not yet invoiced | No          |

### Orders

| Endpoint | Description               | Incremental |
| -------- | ------------------------- | ----------- |
| `order`  | Orders linked to invoices | Yes         |
| `quote`  | Quotes for subscriptions  | Yes         |

### Product Catalog (v2)

| Endpoint      | Description                          | Incremental |
| ------------- | ------------------------------------ | ----------- |
| `item_family` | Item families grouping related items | No          |
| `item`        | Items in the product catalog         | Yes         |
| `item_price`  | Pricing for items                    | Yes         |

### Promotions & Discounts

| Endpoint             | Description                             | Incremental |
| -------------------- | --------------------------------------- | ----------- |
| `coupon`             | Discount coupons                        | No          |
| `promotional_credit` | Promotional credits applied to accounts | No          |
| `gift`               | Gift subscriptions                      | No          |

### Events & Other

| Endpoint                | Description                           | Incremental |
| ----------------------- | ------------------------------------- | ----------- |
| `event`                 | Chargebee events (uses `occurred_at`) | Yes         |
| `comment`               | Comments on resources                 | No          |
| `site_migration_detail` | Site migration details                | No          |

To discover available endpoints:

```bash
sling conns discover CHARGEBEE
```

## Incremental Sync

The Chargebee connector uses time-based incremental sync with the `updated_at` timestamp for most endpoints:

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

### Supported Incremental Endpoints

The following endpoints support incremental sync via `updated_at[after]`:

* `customer`, `subscription`, `invoice`, `credit_note`, `transaction`, `order`, `item`, `item_price`, `payment_source`, `quote`

### Event Endpoint

The `event` endpoint uses `occurred_at` instead of `updated_at` for incremental tracking, fetching events that occurred after the last sync timestamp.

### Full-Refresh Endpoints

These endpoints do not support incremental filtering and always perform a full refresh:

* `coupon`, `item_family`, `comment`, `gift`, `promotional_credit`, `unbilled_charge`, `site_migration_detail`

## Date Fields

All Unix timestamp fields are automatically converted to proper datetime columns with a `_date` suffix:

| Original Field | Converted Field     |
| -------------- | ------------------- |
| `created_at`   | `created_at_date`   |
| `updated_at`   | `updated_at_date`   |
| `cancelled_at` | `cancelled_at_date` |
| `trial_start`  | `trial_start_date`  |
| `trial_end`    | `trial_end_date`    |
| `occurred_at`  | `occurred_at_date`  |
| ...            | ...                 |

## Rate Limiting

The Chargebee API has rate limits:

* **Standard:** 150 requests per minute

The connector automatically:

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

## Common Use Cases

### Sync Core Billing Data

```yaml
source: CHARGEBEE
target: MY_POSTGRES

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

streams:
  customer:
  subscription:
  invoice:
  transaction:
```

### Sync Product Catalog

```yaml
source: CHARGEBEE
target: MY_POSTGRES

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

streams:
  item_family:
    mode: full-refresh
  item:
  item_price:
  coupon:
    mode: full-refresh
```

### Sync Events for Audit Trail

```yaml
source: CHARGEBEE
target: MY_POSTGRES

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

streams:
  event:
```

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/chargebee.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.
