# Store or replace the legacy GitHub token.

> The versioned twin of `PUT /api/settings/github-token`.
> https://koi.dog/docs/api/github/set-git-hub-legacy-token/

`PUT /api/v1/github/legacy-token` · Scope: `config`

Write-only: GitHub is asked about the token first, and one it refuses is not stored (`400 token_refused`). Once the workspace has moved to the App (an active installation covered every project repository when the legacy token was removed) it answers `410 github_app_required`. The timeline records the key ID, action and outcome.

## Headers.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | no | Retry the same request with the same key. [Retry rules](https://koi.dog/docs/api/#retries). |

## Body.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `value` | `string` | yes | A GitHub token crews push with until the workspace moves to the GitHub App. GitHub is asked about it first; one it refuses is not stored. Encrypted at rest and never returned. 1 to 512 characters. |

## Response.

200 OK · JSON object

- **422 validation_failed**: Each schema error appears in `details`.

## Request.

```sh
curl -X PUT https://api.koi.dog/api/v1/github/legacy-token \
    -H "Authorization: Bearer $KOIDOG_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "value": "<value>"
    }'
```

```js
const res = await fetch("https://api.koi.dog/api/v1/github/legacy-token", {
  method: "PUT",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    value: "<value>",
  }),
});
console.log(await res.json());
```

```python
import os

import requests

r = requests.put(
    "https://api.koi.dog/api/v1/github/legacy-token",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
    },
    json={
        "value": "<value>",
    },
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "set": false,
  "source": "settings",
  "login": "string",
  "scopes": [],
  "checkedAt": "string",
  "problem": "string",
  "updatedAt": "string",
  …
}
```
