---
title: "Update Token"
method: PATCH
path: "/api/v1/tokens/{token_id}"
tags: ["API Tokens"]
---

# Update Token

`PATCH /api/v1/tokens/{token_id}`

## Request

- Base URL: `https://public-api.linearb.io`
- URL: `https://public-api.linearb.io/api/v1/tokens/{token_id}`
- Auth: API key in header `x-api-key`
- TypeScript: <https://skmtc.dev/linearb/apis/linearb-api/docs/api/v1/tokens/:token_id/patch.ts> (a function with typed inputs; its response is checked against the schema)

Rename a token, revoke it by setting status to revoked, or change its expiry with expires_at. A token that a detection setting uses cannot be revoked until that setting changes.

## Path parameters

- `token_id` integer, required: Token ID

## Request body

- TokenUpdateRequest
  - `name` string, nullable: New display name.
  - `status` 'revoked', nullable: Set to `revoked` to revoke the token.
  - `expires_at` string, date, nullable: The day the token stops working (UTC, YYYY-MM-DD only). Must be after today and at most 2 years ahead. null = never expires. Omit to keep the current expiry.

## Response `200`

Successful Response

- TokenItem
  - `id` integer, required
  - `name` string, required
  - `prefix` string, required: First characters of the token, to recognize it. Not a secret.
  - `owner_email` string, nullable
  - `role` string, nullable: Role of the account that owns the token.
  - `status` string, required: `active`, `revoked` or `expired`.
  - `source` string, required: `user`, `api` or `otel`.
  - `expires_at` string, date-time, nullable: Expiry time, UTC.
  - `created_at` string, date-time, required: Creation time, UTC.
  - `last_used_at` string, date-time, nullable: Last time the token was used, UTC.

## Other responses

- `400`: Bad Request
- `401`: Unauthorized
- `403`: Forbidden - only admins can manage tokens
- `404`: Token not found
- `405`: Method Not Allowed
- `409`: Conflict - a detection setting uses the token, the token is an otel token, or it is revoked or expired (expiry change)
- `422`: Validation Error
- `500`: Internal Server Error
- `504`: Gateway Timeout

---

[API](https://skmtc.dev/linearb/apis/linearb-api.md) - [All operations](https://skmtc.dev/linearb/apis/linearb-api/llms.txt) - [OpenAPI document](https://skmtc.dev/linearb/apis/linearb-api/revisions/3aea06710db6?raw)
