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

# Loops plugin

> Email platform for software companies with Loops - manage contacts, properties, lists and suppressions, send events and transactional email, build campaigns, workflows, email messages, themes, components and footers, read metrics, and receive signed webhooks.

Use **Loops** through Corsair: one client, typed API calls, and incoming webhooks.

Create a key in Loops under Settings, API ([https://app.loops.so/settings?page=api](https://app.loops.so/settings?page=api)) and paste it as the API key. One key per team; it has full account access, so keep it server-side.

* **Real email.** `events.send` can trigger workflows that email real people, and `transactional.send` delivers a published transactional email to a real inbox. `transactionalId` is the id of a transactional email you created in the Loops dashboard, not the recipient.
* **Upserts.** `contacts.update` creates the contact when no match exists, so it cannot fail with not-found. `contacts.create` answers 409 when the email or userId already exists.
* **Deleting a contact is permanent.** `contacts.delete` removes the contact and its subscriptions; there is no restore call.
* **Custom properties.** Pass them under `customProperties`; values can be strings (max 500 characters), numbers or booleans, and they land on the request body beside the fixed fields, so a key like `email` or `userId` there is rejected. A custom property must exist in the team before a call sets it: create it once with `contacts.createProperty` or in the dashboard. The write example's `planName` needs `contacts.createProperty({ name: 'planName', type: 'string' })` first on a new team.
* **Success envelope.** A 2xx body with `success: false` is still a failure: the plugin throws core's `ApiError` with Loops' message (status 200). Errors keep Loops' answer in `body` (validation failures name a `path` there) and leave out the request body, which holds contact data and template variables.
* **Feature gating.** Campaigns, campaign/transactional/workflow groups, transactional-email management, email messages, workflows and workflow nodes, themes, components, footers, uploads, audience segments and event patterns use Loops' content API. A team without it gets a 401 whose message says the feature is not enabled; the plugin keeps that apart from a bad key and never retries it.
* **Campaign sends.** `campaigns.create` and `campaigns.update` take `scheduling`; `{ method: 'now' }` sends the campaign to its whole audience, so both are `destructive`. Leave `scheduling` out to work on a draft.
* **Workflow edits use revisions.** Workflow and node writes need the workflow's current `expectedRevisionId` (from `workflows.get`) and answer 409 on a stale one. `workflows.changeMailingList` and the node deletes take `dryRun: true`; with queued contacts they answer `status: 'queuedContactsFound'` until you pass `queuedContactPolicy`.
* **Uploads.** `uploads.create` answers a presigned URL; PUT the file there yourself, then call `uploads.complete`.
* **Pagination.** List calls take `perPage` (10 to 50) and `cursor`; the next cursor is `pagination.nextCursor`. `lists.list` and `contacts.listProperties` answer bare arrays.
* **Rate limits.** 10 requests per second per team. Loops sends `x-ratelimit-limit` and `x-ratelimit-remaining` but no Retry-After; the plugin retries a 429 up to three times with exponential backoff, except a used-up quota (50 uploads per 24 hours, the daily preview limit), which it returns at once.
* **Idempotency.** `transactional.send` and `events.send` accept an `idempotencyKey` (max 100 characters). Reusing one within 24 hours answers 409 instead of sending a duplicate. Passing a key also lets the plugin replay a 5xx safely; other writes are never replayed.
* **Inbound webhooks.** Loops signs every delivery the Standard Webhooks way (`webhook-id`, `webhook-timestamp`, `webhook-signature: v1,<base64>`) with the signing secret from Settings → Webhooks (one endpoint per team). Set `webhookSecret`, or store it with `keys.set_webhook_signature`. Verification needs the untouched request body; deliveries more than five minutes off are refused. Events: `contact.created`, `contact.unsubscribed`, `contact.deleted`, `contact.mailingListSubscribed`, `contact.mailingListUnsubscribed`, `transactional.emailSent`, `campaign.emailSent`, `loop.emailSent`, `email.delivered`, `email.softBounced`, `email.hardBounced`, `email.opened`, `email.clicked`, `email.unsubscribed`, `email.resubscribed`, `email.spamReported` and `testing.testEvent`.

**What you get:**

* 82 typed API operations
* 17 incoming webhook event types

## Setup

**1. Install**

```bash npm theme={null}
npm install corsair @corsair-dev/loops better-sqlite3
npm install --save-dev @types/better-sqlite3
```

```bash yarn theme={null}
yarn add corsair @corsair-dev/loops better-sqlite3
yarn add --dev @types/better-sqlite3
```

```bash pnpm theme={null}
pnpm install corsair @corsair-dev/loops better-sqlite3
pnpm install --save-dev @types/better-sqlite3
```

```bash bun theme={null}
bun add corsair @corsair-dev/loops better-sqlite3
bun add --dev @types/better-sqlite3
```

**2. Add the plugin**

```ts corsair.ts theme={null}
import Database from 'better-sqlite3';
import { createCorsair } from 'corsair';
import { loops } from '@corsair-dev/loops';

export const corsair = createCorsair({
	plugins: [
		loops(),
	],
	database: new Database('corsair.db'),
	kek: process.env.CORSAIR_KEK!,
	multiTenancy: true,
	hub: {
		projectApiKey: process.env.CORSAIR_API_KEY!,
		signingSecret: process.env.CORSAIR_SIGNING_SECRET!,
	},
});
```

With `multiTenancy: true`, scope calls with `corsair.withTenant(id)`. See [Quick start](https://docs.corsair.dev/quick-start.md) for KEK + Hub keys, and [Multi-tenancy](https://docs.corsair.dev/concepts/multi-tenancy.md) for account isolation.

**3. Choose authentication**

> [tab] API Key (Recommended)
>
> Store the Loops API key before the first call: `pnpm corsair setup --plugin=loops --tenant=acme api_key=<your-key>` (leave out `--tenant` without `multiTenancy`), or pass it as `key` in the plugin options. With Hub, each tenant enters their own key on the connect page. See [API key auth](https://docs.corsair.dev/concepts/api-key).
>
> ```ts theme={null}
> loops()
> ```
>
> More: [API Key](https://docs.corsair.dev/concepts/api-key)

**4. Connect a tenant**

Mint a connect link and send the tenant to it. Hub hosts the page and delivers the result to your app — see [Connect / OAuth](https://docs.corsair.dev/management/connect).

```ts theme={null}
const { connectUrl } = await corsair.manage.connect.createLink({
	plugin: 'loops',
	tenantId: 'acme',
});
// redirect the user's browser to connectUrl
```

## Example API calls

**List mailing lists**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.loops.api.lists.list({});
```

**Create a contact with a custom property**

```ts theme={null}
const tenant = corsair.withTenant('acme');
await tenant.loops.api.contacts.create({
	email: 'jordan@acme-logistics.com',
	firstName: 'Jordan',
	subscribed: true,
	customProperties: { planName: 'Pro' },
});
```

See the full list on the [API](https://docs.corsair.dev/plugins/loops/api.md) page.

## Webhooks

This plugin registers **17** webhook event types. Configure the provider to POST to your Corsair HTTP handler, then use `webhookHooks` on the plugin factory.

See [Webhooks](https://docs.corsair.dev/plugins/loops/webhooks.md) for every event path and payload shape, and [Webhooks concept](https://docs.corsair.dev/concepts/webhooks.md) for routing.

## What's next

> [card] [API reference](https://docs.corsair.dev/plugins/loops/api.md)
>
> Every `loops.api.*` operation with input and output types.

> [card] [Webhooks](https://docs.corsair.dev/plugins/loops/webhooks.md)
>
> Event paths, payloads, and `webhookHooks` examples.

> [card] [Connect / OAuth](https://docs.corsair.dev/management/connect)
>
> createLink, Hub delivery, and tenant connect flows.

> [card] [Use with agents](https://docs.corsair.dev/mcp-adapters/mcp-adapters)
>
> Expose this plugin's operations as MCP tools.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.