# Rotate an App's OAuth client secret

`POST https://api.koil.co/v1/apps/{appId}/rotate-secret`

Rotate an App's OAuth client secret. Only the secret is replaced; the client id and scopes are kept. A different client is a new App: its Connections' refresh tokens were issued to the old client and would stop renewing.

## 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.

## 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. |
| `appId` | path | yes | string |  |
| `Idempotency-Key` | header | no | 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. |

## Request body

`application/json`

- `clientSecret` (string, required) (min length 1): The client secret the platform issued in place of the App's current one. Write-only: Koil seals it, and never returns it.

Every named shape is in the [OpenAPI document](https://docs.koil.co/openapi.json) under `components.schemas`.

## Example

Rotate a Meta app's secret:

```bash
curl -X POST "https://api.koil.co/v1/apps/{appId}/rotate-secret" \
  -H "Authorization: Bearer $KOIL_API_KEY" \
  -H "Koil-Version: 2026-12-01" \
  -H "Content-Type: application/json" \
  -d '{"clientSecret":"new-app-secret"}'
```

## Response 200

The App, now using the new client secret.

- `kind` (`"app"`, required): The kind of resource this is.
- `mode` (one of `"live"`, `"sandbox"`, required): Which mode the resource belongs to. Live and sandbox resources are separate: a key reads and writes only its own mode's.
- `id` (string, required) (min length 1): Koil App identifier: your OAuth app that authorizes the Connection.
- `issuerId` (string, required) (min length 1): The upstream credential issuer the OAuth app belongs to, such as `facebook` for Facebook Login or `google` for Google. `GET /v1/platforms` lists the issuers each platform connects through.
- `displayName` (string, required)
- `issuerAppId` (string) (min length 1): The platform's own id for your app, where a platform needs one that is not the OAuth client id: LinkedIn's developer application id, the number in your app's Developer Portal URL. Required for an issuer whose platform declares it (`issuerAppId` on `GET /v1/platforms`), refused for any other, and fixed once the App exists.
- `clientId` (string, required) (min length 1): Your app's OAuth client ID. Not a secret: every authorization URL carries it.
- `scopes` (array of string, required): The scopes each Connect Session for the App requests; empty when the App was created without any.
- `webhookVerifyToken` (string, required) (min length 1): Verify token for the platform developer console's webhook callback-URL handshake. Enter it beside Koil's callback URL, `/webhooks/platforms/{platformId}?appId={appId}`.
- `status` (one of `"active"`, `"disabled"`, required)
- `metadata` (object, required): 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.
- `webhookConflicts` (array of object, required): Event families whose callback on your app points somewhere else (TikTok holds one per app and family), so Koil left it alone and events of those families do not reach Koil. Delete that callback and Koil registers its own within a few minutes. Reflects the last reconciliation of an active App; always empty in sandbox mode.
  - `platformId` (string, required)
  - `family` (string, required): The event family as the platform's webhook API names it (TikTok's `event_type`, such as `COMMENT`).
  - `callbackUrl` (string, required): The callback URL your app has for the family.
- `createdAt` (string, date-time, required)
- `updatedAt` (string, date-time, required)

## 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). |
| 404 | `not_found`: The resource does not exist in this Organization and mode. |
| 409 | `conflict`: The request collides with current state: an idempotency key reused with a different payload or still in flight, a run already in progress, a publish that has already started, or a resource that already exists (`meta.resourceType` and `meta.resourceId` name it). Retry only when the response carries `Retry-After` (the key's first request is still in flight), after that many seconds. |
| 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. |
