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

# Onboard a customer

> The full cycle: create the customer project, issue the API key, open the signed link, confirm the connection, send messages and delete the project.

This guide follows the order a partner works in: from registering a customer to a connected number that sends messages. Each customer has **one project** and **one API key**. The organization is where you work as a partner.

> [!NOTE]
>
> Before you start, take the dashboard steps in [Partner API](https://docs.routa.chat/en/partners/overview.md#what-you-do-once-in-the-dashboard): partner profile, redirect origins and partner key.

> [!WARNING]
>
> The Node.js examples use `@routa-chat/sdk/partner`, which is **experimental** and can change in a minor version. Run everything on your server. The partner key and the signing secret never go to the browser.

## 1. Create the customer project

`POST /v1/partner/projects` creates the project. Required scope: `projects:write`.

```bash cURL theme={null}
curl https://api.routa.chat/v1/partner/projects \
  -H "Authorization: Bearer $ROUTA_PARTNER_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Acme Store", "external_ref": "lead_123" }'
```

```ts Node.js theme={null}
import { RoutaPartner } from '@routa-chat/sdk/partner'

const partner = new RoutaPartner(process.env['ROUTA_PARTNER_KEY']!)

const { project, created } = await partner.projects.create({
  name: 'Acme Store',
  externalRef: 'lead_123',
})
```

```json theme={null}
{
  "id": "proj_01J8...",
  "name": "Acme Store",
  "external_ref": "lead_123",
  "environment": "live",
  "created_at": "2026-11-21T13:22:40.812Z"
}
```

`external_ref` is **your** ID for the customer. It has 1 to 128 characters among `A-Z a-z 0-9 . _ : -`, with no spaces. Never use an email address, a phone number or a name. It is unique in the organization and does not change once set.

Repeating the call, on a retry or a second click, returns the same project: `201` the first time and `200` after that. On a `200` response, the `name` you sent is ignored. In the SDK, `created` tells you which of the two happened.

If the plan reached its project limit, the response is `402 project_limit_exceeded`, with the limit in `error.details.limit`. Creating the project is optional: the first signed link also creates it.

## 2. Issue the project API key

`POST /v1/partner/projects/{project_id}/api_keys` issues the key the customer's traffic uses. Required scope: `api_keys:write`.

```bash cURL theme={null}
curl https://api.routa.chat/v1/partner/projects/proj_01J8.../api_keys \
  -H "Authorization: Bearer $ROUTA_PARTNER_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Acme Store", "scopes": ["messages:write", "messages:read"] }'
```

```ts Node.js theme={null}
const key = await partner.projects.apiKeys.create(project.id, {
  name: 'Acme Store',
  scopes: ['messages:write', 'messages:read'],
})

// key.secret is shown only once. Store it now.
```

The key secret appears **only once** in the response. Keep it in your secrets vault. Ask only for the scopes the customer needs, and use `expires_at` and `ip_allowlist` when it makes sense. See [API key scopes](https://docs.routa.chat/en/authentication.md).

> [!WARNING]
>
> Issuing and rotating keys does not accept `Idempotency-Key`. If the response is lost, a retry can issue a second key. If that matters to you, do not retry these calls automatically: in the SDK, use `maxRetries: 0` on them.

## 3. Sign the link and open it

The customer connects their number on a Routa page, opened through a link you sign. Sign the link **when the customer clicks**, because it is valid for 10 minutes.

```ts Node.js theme={null}
import { buildOnboardingLink } from '@routa-chat/sdk/partner'

const url = await buildOnboardingLink({
  partnerId: process.env['ROUTA_PARTNER_ID']!, // ptn_…
  signingSecret: process.env['ROUTA_PARTNER_SIGNING_SECRET']!,
  externalRef: 'lead_123',
  redirectUrl: 'https://app.example.com/connected',
  state: 'value-you-check-against-the-customer-session',
})
```

Open the link with `window.open`, from your page, or in a new tab. The page that opens belongs to Routa and then shows the provider's connection screen. That screen needs a full window or tab and does not work inside an `iframe`.

The link format, the signature and the step-by-step verification are in [Signed link](https://docs.routa.chat/en/partners/signed-link.md).

## 4. Confirm: the redirect is a hint, not proof

When the attempt ends, the customer's browser goes back to your `redirect_url` (if the link had one), with your `state` **unchanged**, and with these parameters:

| Parameter | Value |
| - | - |
| `status` | `completed` or `failed`. |
| `project_id` | The project ID. |
| `channel_id` | The channel ID (`chan_...`), only on success. |
| `error` | A closed code, only on failure. See [Signed link](https://docs.routa.chat/en/partners/signed-link.md#returning-to-your-site). |

Anyone can forge a request to your `redirect_url`. Check your `state` against the customer session, then **retrieve the project and trust only that**:

```bash cURL theme={null}
curl https://api.routa.chat/v1/partner/projects/proj_01J8... \
  -H "Authorization: Bearer $ROUTA_PARTNER_KEY"
```

```ts Node.js theme={null}
const detail = await partner.projects.retrieve(project.id)
const connected = detail.channels.some(channel => channel.status === 'active')
```

```json theme={null}
{
  "id": "proj_01J8...",
  "name": "Acme Store",
  "external_ref": "lead_123",
  "environment": "live",
  "created_at": "2026-11-21T13:22:40.812Z",
  "channels": [{ "id": "chan_01J8...", "status": "active" }]
}
```

No key, secret or provider credential appears in the URL. Events also reach your webhook, with the same `project_id`. If you do not have a webhook yet, poll the project at growing intervals and with a deadline: the customer may never finish.

To see the numbers of all your customers at once, use [`GET /v1/partner/channels`](https://docs.routa.chat/en/api-reference/endpoint/partner/list-channels). It accepts the `status`, `project_id` and `external_ref` filters. To find the projects that never finished the link, use `has_channel=false` in [`GET /v1/partner/projects`](https://docs.routa.chat/en/api-reference/endpoint/partner/list-projects).

## 5. Send with the project key and receive everything on one webhook

Use the API key from step 2 on the usual data routes, such as `POST /v1/messages`:

```ts Node.js theme={null}
import { Routa } from '@routa-chat/sdk'

const routa = new Routa(projectApiKey)

await routa.messages.send({
  channel: 'chan_01J8...',
  to: '+5581999999999',
  text: 'Hi! Your order is confirmed.',
})
```

To receive the events of **every** customer in one place, set the [organization webhook](https://docs.routa.chat/en/partners/webhook.md). Each event carries the `project_id` and the `external_ref`, so you route by your own ID without keeping a lookup table.

## 6. Delete a customer project to free the slot

The plan limits the projects in the organization. An abandoned link or a customer who left still counts. Delete the project to free the slot.

```bash cURL theme={null}
curl -X DELETE https://api.routa.chat/v1/partner/projects/proj_01J8... \
  -H "Authorization: Bearer $ROUTA_PARTNER_KEY"
```

```ts Node.js theme={null}
let result = await partner.projects.delete(project.id)
while (result.status === 'deleting') {
  result = await partner.projects.delete(project.id)
}
```

Deleting requires the opt-in `projects:delete` scope, which a new key does not have. The deletion removes the project and everything it owns: messages, templates, events, contacts, keys, webhook endpoints, media files and disabled channels, whose numbers become free again. The plan, the allowance, the audit log and the partner keys of the organization do not change. Nothing changes on WhatsApp.

| Response | Meaning |
| - | - |
| `204` | The project was deleted. |
| `202` | The project is large and only part of it was deleted. Repeat the same call until you get `204`. |
| `409 project_not_deletable` | See `error.details.reason`: `has_enabled_channel` (there is a channel that is not `disabled`) or `last_project` (the organization cannot be left without projects). |
| `404 project_not_found` | The project does not exist or was not created through the Partner API. |

To delete a project that still has a channel, the channel must be `disabled`. See [Partner keys](https://docs.routa.chat/en/partners/partner-keys.md#delete-a-disabled-channel).


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