# Export an `oauth` Connection's current platform grant

`GET https://api.koil.co/v1/connections/{connectionId}/credential`

Export an `oauth` Connection's current platform grant. Requires an API key with the `credentials:export` permission. Any other method is refused with `not_supported`: Koil exports only what a platform issued to an authorization it ran, never a key someone submitted.

## Authorization

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. Requires the `credentials:export` permission.

## Parameters

| Name | In | Required | Type | Description |
| --- | --- | --- | --- | --- |
| `Koil-Version` | header | yes | `"2026-12-01"` | 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. |
| `connectionId` | path | yes | string |  |

## Example

```bash
curl -X GET "https://api.koil.co/v1/connections/{connectionId}/credential" \
  -H "Authorization: Bearer $KOIL_API_KEY" \
  -H "Koil-Version: 2026-12-01"
```

## Response 200

The Connection's grant as Koil holds it, in the shape `POST /v1/connections` takes as `grant`. Koil renews a renewable access token ahead of `expiresAt`, so it is current unless renewal is failing; nothing is renewed for the export.

- `connectionId` (string, required) (min length 1): Koil Connection identifier.
- `method` (`"oauth"`, required): Only `oauth` Connections are exported: Koil exports what a platform issued to a flow it ran, never a key someone submitted (`not_supported`).
- `appId` (string, required) (min length 1): Koil App identifier: your OAuth app that authorizes the Connection.
- `clientUserId` (string) (max length 255): Your own identifier for the end user the Connection belongs to.
- `grant` (object, required): An end user's OAuth grant, issued to your own app.
  - `accessToken` (string, required) (min length 1): The platform access token.
  - `refreshToken` (string) (min length 1): The platform refresh token, where the platform issued one (TikTok, Google, LinkedIn). Koil uses it to renew the access token before it expires; a platform that rotates refresh tokens (TikTok) invalidates the previous one on each renewal.
  - `expiresAt` (string, date-time): When the access token expires. Required with `refreshToken` on create, since Koil renews only a token it knows the expiry of. Absent for a token that does not expire, such as a WhatsApp system-user token.
  - `refreshTokenExpiresAt` (string, date-time): When the refresh token itself expires, where the platform says (TikTok's and LinkedIn's `refresh_token_expires_in`, about a year after the end user authorized). Only with `refreshToken`. Koil dates the Connection's `credential.reauthorizeBy` by it and makes the Connection `reauthorization_required` 14 days ahead of it. Absent when the platform set no such date or Koil does not know it. A date already past is refused, since such a refresh token renews nothing.
- `scopes` (array of string): The scopes the grant holds. Absent when Koil does not know them, which is not a grant of none.

## Errors

Every error has the same shape: `{ "error": { "code", "message", "meta", "requestId" } }`. [Errors →](https://docs.koil.co/concepts/errors)

| Status | Meaning |
| --- | --- |
| 400 | `validation_error`: The request does not match the operation's input schema, fails an admission check, or the platform refused its content. `meta.violations` names every problem. `not_supported`: The platform, collection or resource does not offer this operation, such as exporting a `key` Connection's credential, which Koil never returns. |
| 401 | `unauthorized`: No API key, or a key Koil does not accept (unknown, revoked, or with a prefix that does not match its mode). |
| 403 | `permission_denied`: The API key is valid but lacks a permission the operation requires; `meta.required` names it. Use a key created with that permission. `scope_insufficient`: The credential lacks a scope the operation needs; `meta` names the missing scopes. `connection_invalid`: The platform credential behind the Profile no longer works; the end user must re-authorize. |
| 404 | `not_found`: The resource does not exist in this Organization and mode. |
| 429 | `rate_limit_exceeded`: Koil's own rate limit for the key, Organization, Profile, or client address is spent (`meta.budgets` names which); retry after `Retry-After` seconds. `platform_rate_limit`: The platform throttled the call or the platform quota is spent; retry after `Retry-After` seconds. |
| 500 | `internal`: Koil or the platform failed, and the status says which: 500 when Koil failed, including a platform refusing how Koil made the call; 502 when the platform failed or answered something Koil cannot use; 504 when Koil's call to the platform timed out. The message is generic; retry with backoff. |
| 503 | `service_unavailable`: A service Koil needs to accept the request (API key validation or rate limiting) is unavailable. Nothing was attempted; retry after `Retry-After` seconds. |
| default | Any other failure. `error.code` names it; the HTTP status follows from it. |
