# Start a connect

POST

/v1/connections

```sh
curl --request POST \
  --url https://example.com/v1/connections \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{ "app": "example", "appId": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "projectId": "example", "permissions": [ "example" ], "for": "me", "label": "example", "reconnects": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0", "number": "example", "replaceInbound": true }'
```

Makes a connect request for the caller’s own account (`for: 'me'`, the default; signed in as a person) or the company’s (`for: 'company'`; a tenant admin only). Send the person to the request’s `connectUrl`, or call `POST /v1/connections/requests/{requestId}/start` for the app’s consent page. The company and each person keep one connection per account, registration and environment: a connect lands on its owner’s connection of the account signed in to, which is known only at the finish, or makes a new one. To connect a given connection again, name it in `reconnects`; the same account is required at the finish. A run that needs a connection it lacks makes its own request and waits for it (`waitingFor.connections` on the run). An app connected without a browser (`texts`) has no consent page: the connect names the account (`number`), the server looks it up with the registration’s credential, and the request comes back `connected`, with `connectionId`; its `connectUrl` page only shows it connected, and `expiresAt` ends only a `pending` request. Connecting a number moves its inbound texts onto Kindgi’s messaging profile, whose outbound settings then apply; a reconnect names the connection’s own number and looks it up again with the registration’s current credential, which is how a `credential-refused` connection works again. A key or session limited to a project is refused, `403 permission-denied`: a connection reaches every project.

## Authorizations

- **[bearerAuth](https://docs.kindgi.com/v0.8.1/reference/api.md#bearerauth)**

## Parameters

### Header Parameters

**Idempotency-Key**

string

\>= 1 characters

Caller-supplied idempotency key, scoped to the caller: the same key from someone else in the workspace is their own request (from 0.1.5). Retries with the same key return the original response byte-identical (per `docs/API-ROUTE-CONVENTIONS.md` §3.1). A retry sent while the first request still runs is answered `409 idempotency-key-in-flight` with `Retry-After`, on a runtime whose store holds keys (from 0.1.5); retry after it, and you get the first request’s answer. An answer that carries a secret (a new API key or public run token, a session token, a generated signing secret) isn’t kept: a retry gets `409 idempotency-key-replay-withheld`, with the first request’s status and when it succeeded (from 0.1.5). A request whose key store can’t be read before it runs is answered `503 idempotency-store-unavailable` with `Retry-After`: nothing ran, so retry with the same key (from 0.3.0).

## Request Bodyrequired

application/json

object

**app**

required

The app’s entry id.

string

/^\[a-z]\[a-z0-9-]{1,31}$/

**appId**

Which registration, when the workspace has more than one for the app.

string format: uuid

**projectId**

When given, the registration must allow this project.

string

\>= 1 characters

**permissions**

required

The entry’s permission keys to ask for.

Array\<string>

\>= 1 items <= 64 items

**for**

`me`: the caller’s own account (signed in as a person). `company`: the company’s account; a tenant admin only.

string

default: me

Allowed values: me company

**label**

The connection’s name, trimmed, with no control, format or invisible characters (such as bidi overrides, zero-width characters or line separators); another live connection of the same app, owner and env can’t have it, ignoring case, an emoji’s variation selector and how accented letters are encoded. Absent: the account’s label. A reconnect keeps the connection’s name, and doesn’t check this one against the others.

string

\>= 1 characters <= 100 characters

**reconnects**

The connection to connect again: a live one of this connect’s own owner (the caller’s for `for: 'me'`, the company’s for `for: 'company'`), on the same registration and environment. Any other id is `404 connection-not-found`, the same answer as for one that doesn’t exist. The same account is required at the finish, and the connection keeps its name. It asks for the permissions it lists and those the connection holds. A grant short of what the connection holds leaves it as it was, and the connect is declined with `missing` unless the connection is working and already holds what was asked. Absent: a person’s connect, like the company’s, asks only for the permissions it lists; at the finish it lands on the owner’s connection of the account signed in to, when there is one (when it’s connected, `reconnected` is true; a grant short of what that connection holds leaves it as it was, and the connect is declined with `missing` unless the connection is working and already holds what was asked), else makes a new one. For a number (`texts`), a reconnect names the connection’s own number (any other is `409 connection-account-mismatch`), looks it up again with the registration’s current credential, and makes the connection working.

string format: uuid

**number**

A `texts` connect’s, and required there: the number to connect, in E.164 (`+15551234567`). `400 bad-input` for any other app.

string

/^\\+\[1-9]\[0-9]{6,14}$/

**replaceInbound**

A `texts` connect’s: `true` connects even though the number’s inbound texts go somewhere else today (`409 inbound-in-use` without it). Connecting moves the number onto Kindgi’s messaging profile, whose outbound settings then apply; the removal puts the old inbound back. Only `true`; `400 bad-input` for any other app.

boolean

## Responses

### 201

Connect request made.

application/json

A connect: the owner goes to `connectUrl`, consents at the app, and comes back. A run that needs a connection it lacks waits on one. An app connected without a browser (`texts`) has no such step: its request is `connected` from the start.

object

**requestId**

required

string format: uuid

**envName**

required

string

**appId**

required

string format: uuid

**app**

required

The app’s entry id.

string

**owner**

required

Who owns a connection: one member (`kind: member`, with their `userId`), or the company (`kind: company`, the workspace’s own account).

object

**kind**

required

string

Allowed values: member company

**userId**

The member. Present when `kind` is `member`.

string

**permissions**

required

The permissions asked for: the ones needed, and the ones already granted.

Array\<string>

**says**

required

What each asks for, in plain words.

Array\<string>

**reconnects**

The connection it connects again; the same account is required.

string format: uuid

**label**

The name asked for the connection it makes. A reconnect keeps the connection’s.

string

**runId**

The run that waits for it.

string

**name**

The tool’s name for the connection, when a run waits.

string

**startedBy**

Who started it last: `<kind>:<id>`. Only they may finish it.

string

**state**

required

string

Allowed values: pending connected declined expired failed

**failure**

Why it failed: `account-mismatch`, `app-refused`, `store-write-failed`.

string

**missing**

The permissions the app granted less than asked.

Array\<string>

**installations**

A GitHub App’s, while it’s `pending`: the app’s installations the person’s GitHub account reaches, when the finish found several and none was picked. They pick one and start again with `installationId`, or install the app on another account with `newInstallation`.

Array\<object>

A GitHub App installation the person can reach.

object

**installationId**

required

string

**account**

required

The account it’s on: its login, or the enterprise’s slug.

object

**id**

required

The account’s stable id at the app.

string

**label**

required

What people see: an email address, a login, a Page’s name.

string

**accounts**

For an app that connects through Kindgi’s own app, while the request is `pending`: the accounts the business shared that fit the app (Facebook Pages, or Instagram accounts), when the finish found several and none was picked. They pick one and start again with `accountId`.

Array\<object>

Whose account a connection is at the app.

object

**id**

required

The account’s stable id at the app.

string

**label**

required

What people see: an email address, a login, a Page’s name.

string

**connectionId**

The connection it made, or the one it reconnected. A `declined` connect names it too when it kept what the app allowed; one that left the connection as it was names none.

string format: uuid

**connectUrl**

required

Where the owner starts. For an app connected without a browser (`texts`), the request comes back `connected`, with `connectionId`, and its page only shows it connected: there is nothing to open.

string format: uri

**expiresAt**

required

When a `pending` request expires; it ends no other.

string format: date-time

**createdAt**

required

string format: date-time

**createdBy**

required

string

##### Example

```json
{
  "owner": {
    "kind": "member"
  },
  "state": "pending"
}
```

### 400

Malformed body, unknown field, a `reconnects` that isn’t a UUID, a `label` that isn’t 1 to 100 characters with no control, format or invisible characters (such as bidi overrides, zero-width characters or line separators), a `number` that isn’t E.164 or a `replaceInbound` that isn’t `true` (`bad-input`, `details.field`); `number` missing on a `texts` connect, or `number` or `replaceInbound` on any other app’s (`bad-input`, `details.field`); `for: 'me'` from a credential that is not a person (`bad-input`); or no registration that fits (`connection-app-invalid`, `connection-app-unknown-entry`).

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 401

Missing / malformed / expired / revoked bearer token.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 403

`for: 'company'` from a caller who is not a tenant admin (`permission-denied`).

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 404

No registration with that `appId` (`connection-app-not-found`); or `reconnects` names no live connection of the connect’s own owner on that registration and environment, whether another owner’s, another registration’s or environment’s, removed or unknown (`connection-not-found`, `details.field` `reconnects`).

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 409

Idempotency-Key was reused with a different body; another live connection of the same app, owner and env has that `label`, ignoring case, an emoji’s variation selector and how accented letters are encoded, and the connect isn’t a reconnect (`connection-label-taken`, `details.field` `label`); or the connection is still being disconnected: disconnect it again to finish, then connect (`connection-removing`). For a number (`texts`): its inbound texts go somewhere else today, `details.host` the webhook’s host or else `details.profile` the messaging profile it is on; connect again with `replaceInbound: true` to move it onto Kindgi’s (`inbound-in-use`); it is connected through another registration or env of the tenant, `details.appId` and `details.envName` (`number-in-use`); or a reconnect names another number than the connection’s, which the message names (`connection-account-mismatch`). Or `idempotency-key-in-flight` (with `Retry-After`): a request with the same `Idempotency-Key` still runs, so this one wasn’t run; send it again after `Retry-After` to get that request’s answer.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

#### Headers

**Retry-After**

integer

\>= 1

Whole seconds to wait before sending the request again, at least 1. Sent with the codes the answer names as sending it, so it may be absent.

### 413

The request body is over the API’s limit (`request-too-large`; `details.maxBytes` says how much).

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 429

`rate-limit-exceeded` with `details.limit: "api-requests"`, on a runtime that sets workspace limits (Kindgi Cloud): this workspace’s limit on API requests a minute is reached, so the request wasn’t run; `Retry-After` says when to send it again.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

#### Headers

**Retry-After**

integer

\>= 1

Whole seconds to wait before sending the request again, at least 1. Sent with the codes the answer names as sending it, so it may be absent.

### 500

Server error (unmapped domain code or framework crash).

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 502

The provider refused the registration’s credential or the lookup of the number (`connection-app-refused`, with the provider’s code in the message). Update the registration’s secret, or check the number at the provider, and connect again.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

### 503

The `Idempotency-Key` store (`idempotency-store-unavailable`) or the authorization store (`authz-backend-unavailable`) couldn’t be reached before the request ran, or the database was too busy for its authorization check (`database-busy`), so nothing was changed; `Retry-After` (whole seconds) says when to try again with the same key. Or `tenant-state-unavailable` (with `Retry-After`), on a runtime serving many workspaces: the workspace’s state couldn’t be read, so nothing was changed.

application/json

object

**error**

required

object

**code**

required

Stable machine-readable discriminant. Values match domain error codes (see `docs/API-ROUTE-CONVENTIONS.md` §4.3).

string

**message**

required

string

**details**

Optional, kind-specific.

object

**_key_**

additional properties

any

**requestId**

required

Server-assigned request id; also echoed via `X-Request-Id` header.

string

##### Examplegenerated

```json
{
  "error": {
    "code": "example",
    "message": "example",
    "details": {},
    "requestId": "example"
  }
}
```

#### Headers

**Retry-After**

integer

\>= 1

Whole seconds to wait before sending the request again, at least 1. Sent with the codes the answer names as sending it, so it may be absent.

## See also

- [`GET /v1/connections`: List connections](https://docs.kindgi.com/v0.8.1/reference/api/operations/connectionslist.md)
- [Kindgi 0.5.0](https://docs.kindgi.com/v0.8.1/releases/0.5.0.md)
- [Error code `authz-backend-unavailable`](https://docs.kindgi.com/v0.8.1/reference/errors.md#authz-backend-unavailable)
- [Error code `bad-input`](https://docs.kindgi.com/v0.8.1/reference/errors.md#bad-input)
- [Error code `connection-account-mismatch`](https://docs.kindgi.com/v0.8.1/reference/errors.md#connection-account-mismatch)
- [Error code `connection-app-invalid`](https://docs.kindgi.com/v0.8.1/reference/errors.md#connection-app-invalid)
- [Error code `connection-app-not-found`](https://docs.kindgi.com/v0.8.1/reference/errors.md#connection-app-not-found)
- [Error code `connection-app-refused`](https://docs.kindgi.com/v0.8.1/reference/errors.md#connection-app-refused)
- [Error code `connection-app-unknown-entry`](https://docs.kindgi.com/v0.8.1/reference/errors.md#connection-app-unknown-entry)
- [Error code `connection-label-taken`](https://docs.kindgi.com/v0.8.1/reference/errors.md#connection-label-taken)
- [Error code `connection-not-found`](https://docs.kindgi.com/v0.8.1/reference/errors.md#connection-not-found)
- [Error code `connection-removing`](https://docs.kindgi.com/v0.8.1/reference/errors.md#connection-removing)
- [Error code `database-busy`](https://docs.kindgi.com/v0.8.1/reference/errors.md#database-busy)
- [Error code `idempotency-key-in-flight`](https://docs.kindgi.com/v0.8.1/reference/errors.md#idempotency-key-in-flight)
- [Error code `idempotency-store-unavailable`](https://docs.kindgi.com/v0.8.1/reference/errors.md#idempotency-store-unavailable)
- [Error code `inbound-in-use`](https://docs.kindgi.com/v0.8.1/reference/errors.md#inbound-in-use)
- [Error code `number-in-use`](https://docs.kindgi.com/v0.8.1/reference/errors.md#number-in-use)
- [Error code `permission-denied`](https://docs.kindgi.com/v0.8.1/reference/errors.md#permission-denied)
- [Error code `rate-limit-exceeded`](https://docs.kindgi.com/v0.8.1/reference/errors.md#rate-limit-exceeded)
- [Error code `request-too-large`](https://docs.kindgi.com/v0.8.1/reference/errors.md#request-too-large)
- [Error code `tenant-state-unavailable`](https://docs.kindgi.com/v0.8.1/reference/errors.md#tenant-state-unavailable)
- [Every error code](https://docs.kindgi.com/v0.8.1/reference/errors.md)
