Saltar al contenido

Update an API key

Módulo Settings

PATCH/api-keys/{id}apiKeys.update

An org-scoped API key with capability scopes and expiry. The secret is shown once and stored hashed. Updates the fields sent; omitted fields are unchanged. Requires `If-Match` with the current `ETag`: a stale tag returns 412 and a missing tag returns 428.

  • Requiere la capacidad org.api_keys.manage.
  • Alcances de OAuth: org.
  • Envía If-Match con el ETag que leíste. Una etiqueta desactualizada devuelve 412; si falta, devuelve 428.
  • Estados de error: 400, 401, 404, 412, 422, 428, 429. Los errores son detalles de problema RFC 9457.

Parámetros de ruta y de consulta

apiKeys.update: Parámetros de ruta y de consulta
CampoTipoObligatorioDescripción
idstring (uuid)SíIdentifier of the api key.

Cuerpo de la solicitud: ApiKeyUpdate

apiKeys.update: ApiKeyUpdate
CampoTipoObligatorioDescripción
namestringNoKey name.Restricciones: length 1 to 300
service_account_idstring (uuid) | nullNoIdentifier of the service account.
scopesarray of stringNoCapability groups the key may use.
expires_atstring (date-time)NoExpiry.
{
  "name": "Accounting Sync",
  "service_account_id": "0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f",
  "scopes": [
    "finance"
  ],
  "expires_at": "2026-10-08T14:30:00Z"
}

Respuesta 200: ApiKey

apiKeys.update: ApiKey
CampoTipoObligatorioDescripción
idstring (uuid)SíIdentifier of the api key.
org_idstring (uuid)SíIdentifier of the owning organization, derived from the parent row and never accepted from the caller.
created_atstring (date-time)SíWhen the row was created.
created_bystring (uuid) | nullSíIdentifier of the person who created the row; null when a seed, platform or system process created it.
updated_atstring (date-time)SíWhen the row was last updated.
updated_bystring (uuid) | nullSíIdentifier of the person who last updated the row; null when a seed, platform or system process updated it.
namestringSíKey name.Restricciones: length 1 to 300
service_account_idstring (uuid) | nullSíIdentifier of the service account.
scopesarray of stringSíCapability groups the key may use.
expires_atstring (date-time)SíExpiry.
prefixstringSíVisible key prefix.Restricciones: pattern ^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$
last_used_atstring (date-time) | nullSíLast use.
revoked_atstring (date-time) | nullSíWhen it was revoked.
revoked_bystring (uuid) | nullSíIdentifier of the person who revoked the key.
{
  "id": "0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f",
  "org_id": "0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f",
  "created_at": "2026-10-08T14:30:00Z",
  "created_by": "0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f",
  "updated_at": "2026-10-08T14:30:00Z",
  "updated_by": "0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f",
  "name": "Accounting Sync",
  "service_account_id": "0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f",
  "scopes": [
    "finance"
  ],
  "expires_at": "2026-10-08T14:30:00Z",
  "prefix": "xos_live_7Hq2",
  "last_used_at": "2026-10-08T14:30:00Z",
  "revoked_at": "2026-10-08T14:30:00Z",
  "revoked_by": "0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f"
}

Ejemplos de código

curl -X PATCH "$XOS_BASE_URL/api-keys/0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f" \
  -H "Authorization: Bearer $XOS_API_KEY" \
  -H 'If-Match: W/"etag-from-your-last-read"' \
  -H "Content-Type: application/json" \
  -d '{"name":"Accounting Sync","service_account_id":"0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f","scopes":["finance"],"expires_at":"2026-10-08T14:30:00Z"}'
const { data, etag } = await xos.apiKeys.update("0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f", {
    "name": "Accounting Sync",
    "service_account_id": "0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f",
    "scopes": [
      "finance"
    ],
    "expires_at": "2026-10-08T14:30:00Z"
  }, { ifMatch: etag });
response = xos.api_keys.update("0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f", {"name": "Accounting Sync", "service_account_id": "0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f", "scopes": ["finance"], "expires_at": "2026-10-08T14:30:00Z"}, if_match=etag)
xos api-keys update 0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f --data '{"name":"Accounting Sync","service_account_id":"0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f","scopes":["finance"],"expires_at":"2026-10-08T14:30:00Z"}' --if-match auto