Create a Koil Connection from a credential you already hold

POST
/v1/connections

Create a Koil Connection from a credential you already hold: for method: "oauth", a platform grant an end user gave your App, so adopting Koil costs no reauthorization; for method: "key", a key the brand gave you, as key: the config and secret its issuer declares (GET /v1/issuers), with no App. Requires an Idempotency-Key. The credential is first checked with the platform, and refused with connection_invalid if the platform rejects it, with nothing stored. It always creates: a credential for an account that already has a Connection under the same issuer, App (none for a key) and clientUserId is refused with conflict (409), whose meta.resourceId names that Connection; replace its credential with PUT /v1/connections/{connectionId}/credential. The new Connection takes the request's metadata. A grant whose access token has expired is renewed first and its fresh token checked, and refused if the platform refuses to renew it or nothing can. A key's secret is sealed and never returned. For method: "oauth", the answer names the App's scopes the grant lacks (missingScopes), as a completed Connect Session does.

Authorization

bearerAuth
AuthorizationBearer <token>

An API key from the Koil admin console, sent as Authorization: Bearer <key>. A live key starts koil_live_ and a sandbox key koil_sandbox_; the key alone selects the Organization and mode. See https://docs.koil.co/concepts/authentication.

In: header

Header Parameters

Koil-Version*string

The dated API version the request is written against; it fixes the request and response shapes. Every response echoes the version it is rendered in.

Value in"2026-12-01"
Idempotency-Key*string

A unique key for this request, scoped to the Organization and operation. Retrying with the same key and payload returns the first result instead of repeating the work, or runs a request that failed again; the same key with a different payload is refused with 409 conflict. Keys expire 24 hours after first use, and a request still in flight after 15 minutes releases its key to a retry with the same payload.

Match\S
Length1 <= length <= 255

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

method*string

From a grant an end user gave your App.

appId*string

Koil App identifier: your OAuth app that authorizes the Connection.

Length1 <= length
clientUserId?string

Your own identifier for the end user the Connection belongs to.

Length1 <= length <= 255
grant*

An end user's OAuth grant, issued to your own app.

scopes?array<>

The scopes (or, for a key, the roles) the credential holds: at least one, each once. Optional: omitted, Koil records what the platform reports; sent, Koil keeps these. An issuer that reports none needs them declared.

Items1 <= items
metadata?

Your own key-value pairs, up to 50 keys of at most 40 characters with string values of at most 500. An update merges into what is stored, and a key set to "" is removed.

Propertiesproperties <= 50
method*string

From a key the brand gave you, verified with the platform before anything is stored. There is no App.

issuerId*string

The issuer the key is for, such as app_store_connect for an App Store Connect API key. GET /v1/issuers lists the issuers that take a key, with the fields each declares.

Length1 <= length
key*

The key the brand gave you, in the two halves its issuer declares (GET /v1/issuers: methods.key).

clientUserId?string

Your own identifier for the end user the Connection belongs to.

Length1 <= length <= 255
scopes?array<>

The scopes (or, for a key, the roles) the credential holds: at least one, each once. Optional: omitted, Koil records what the platform reports; sent, Koil keeps these. An issuer that reports none needs them declared.

Items1 <= items
metadata?

Your own key-value pairs, up to 50 keys of at most 40 characters with string values of at most 500. An update merges into what is stored, and a key set to "" is removed.

Propertiesproperties <= 50

Response Body

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/v1/connections" \  -H "Koil-Version: 2026-12-01" \  -H "Idempotency-Key: string" \  -H "Content-Type: application/json" \  -d '{    "method": "oauth",    "appId": "app_123",    "clientUserId": "customer-user-123",    "grant": {      "accessToken": "EAAG...",      "expiresAt": "2026-08-30T09:30:00.000Z"    },    "metadata": {      "accountId": "acct_42"    }  }'

{  "kind": "connection",  "mode": "live",  "id": "conn_123",  "issuerId": "facebook",  "method": "oauth",  "oauth": {    "appId": "app_123"  },  "clientUserId": "customer-user-123",  "status": "active",  "credential": {    "scopes": [      "instagram_basic",      "pages_show_list",      "pages_read_engagement"    ]  },  "metadata": {    "accountId": "acct_42"  },  "createdAt": "2026-07-01T09:30:00.000Z",  "updatedAt": "2026-07-01T09:30:00.000Z"}

{  "error": {    "code": "validation_error",    "message": "string",    "meta": {      "violations": [        {          "code": "string",          "path": "string",          "message": "string"        }      ],      "budgets": [        "string"      ],      "profileIds": [        "string"      ],      "required": [        "string"      ],      "limit": 0,      "resourceType": "string",      "resourceId": "string",      "reason": "string",      "refusalReason": "messaging_window_closed",      "property1": null,      "property2": null    },    "requestId": "string"  }}
{  "error": {    "code": "validation_error",    "message": "string",    "meta": {      "violations": [        {          "code": "string",          "path": "string",          "message": "string"        }      ],      "budgets": [        "string"      ],      "profileIds": [        "string"      ],      "required": [        "string"      ],      "limit": 0,      "resourceType": "string",      "resourceId": "string",      "reason": "string",      "refusalReason": "messaging_window_closed",      "property1": null,      "property2": null    },    "requestId": "string"  }}
{  "error": {    "code": "validation_error",    "message": "string",    "meta": {      "violations": [        {          "code": "string",          "path": "string",          "message": "string"        }      ],      "budgets": [        "string"      ],      "profileIds": [        "string"      ],      "required": [        "string"      ],      "limit": 0,      "resourceType": "string",      "resourceId": "string",      "reason": "string",      "refusalReason": "messaging_window_closed",      "property1": null,      "property2": null    },    "requestId": "string"  }}
{  "error": {    "code": "validation_error",    "message": "string",    "meta": {      "violations": [        {          "code": "string",          "path": "string",          "message": "string"        }      ],      "budgets": [        "string"      ],      "profileIds": [        "string"      ],      "required": [        "string"      ],      "limit": 0,      "resourceType": "string",      "resourceId": "string",      "reason": "string",      "refusalReason": "messaging_window_closed",      "property1": null,      "property2": null    },    "requestId": "string"  }}
{  "error": {    "code": "validation_error",    "message": "string",    "meta": {      "violations": [        {          "code": "string",          "path": "string",          "message": "string"        }      ],      "budgets": [        "string"      ],      "profileIds": [        "string"      ],      "required": [        "string"      ],      "limit": 0,      "resourceType": "string",      "resourceId": "string",      "reason": "string",      "refusalReason": "messaging_window_closed",      "property1": null,      "property2": null    },    "requestId": "string"  }}
{  "error": {    "code": "validation_error",    "message": "string",    "meta": {      "violations": [        {          "code": "string",          "path": "string",          "message": "string"        }      ],      "budgets": [        "string"      ],      "profileIds": [        "string"      ],      "required": [        "string"      ],      "limit": 0,      "resourceType": "string",      "resourceId": "string",      "reason": "string",      "refusalReason": "messaging_window_closed",      "property1": null,      "property2": null    },    "requestId": "string"  }}
{  "error": {    "code": "validation_error",    "message": "string",    "meta": {      "violations": [        {          "code": "string",          "path": "string",          "message": "string"        }      ],      "budgets": [        "string"      ],      "profileIds": [        "string"      ],      "required": [        "string"      ],      "limit": 0,      "resourceType": "string",      "resourceId": "string",      "reason": "string",      "refusalReason": "messaging_window_closed",      "property1": null,      "property2": null    },    "requestId": "string"  }}
{  "error": {    "code": "validation_error",    "message": "string",    "meta": {      "violations": [        {          "code": "string",          "path": "string",          "message": "string"        }      ],      "budgets": [        "string"      ],      "profileIds": [        "string"      ],      "required": [        "string"      ],      "limit": 0,      "resourceType": "string",      "resourceId": "string",      "reason": "string",      "refusalReason": "messaging_window_closed",      "property1": null,      "property2": null    },    "requestId": "string"  }}
{  "error": {    "code": "validation_error",    "message": "string",    "meta": {      "violations": [        {          "code": "string",          "path": "string",          "message": "string"        }      ],      "budgets": [        "string"      ],      "profileIds": [        "string"      ],      "required": [        "string"      ],      "limit": 0,      "resourceType": "string",      "resourceId": "string",      "reason": "string",      "refusalReason": "messaging_window_closed",      "property1": null,      "property2": null    },    "requestId": "string"  }}
{  "error": {    "code": "validation_error",    "message": "string",    "meta": {      "violations": [        {          "code": "string",          "path": "string",          "message": "string"        }      ],      "budgets": [        "string"      ],      "profileIds": [        "string"      ],      "required": [        "string"      ],      "limit": 0,      "resourceType": "string",      "resourceId": "string",      "reason": "string",      "refusalReason": "messaging_window_closed",      "property1": null,      "property2": null    },    "requestId": "string"  }}
{  "error": {    "code": "validation_error",    "message": "string",    "meta": {      "violations": [        {          "code": "string",          "path": "string",          "message": "string"        }      ],      "budgets": [        "string"      ],      "profileIds": [        "string"      ],      "required": [        "string"      ],      "limit": 0,      "resourceType": "string",      "resourceId": "string",      "reason": "string",      "refusalReason": "messaging_window_closed",      "property1": null,      "property2": null    },    "requestId": "string"  }}