Saltar al contenido

Create an API key

Módulo Settings

POST/api-keysapiKeys.create

Creates an API key with scopes and an expiry, optionally for a service account, through `app.create_api_key`. The full secret is returned once; only its hash is stored. Requires `Idempotency-Key`; a replay returns the original response. A rule that refuses the request returns 422 with `refusal` and `reason`.

  • Requiere la capacidad org.api_keys.manage.
  • Alcances de OAuth: org.
  • Envía el encabezado Idempotency-Key. Una repetición con la misma clave devuelve la respuesta original.
  • Estados de error: 400, 401, 409, 422, 429. Los errores son detalles de problema RFC 9457.

Cuerpo de la solicitud: ApiKeyCreate

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

Respuesta 201: ApiKeySecret

apiKeys.create: ApiKeySecret
CampoTipoObligatorioDescripción
api_key_idstring (uuid)SíIdentifier of the API key.
secretstringSíThe full key. Shown once; only its hash is stored.Restricciones: length 1 to any
{
  "api_key_id": "0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f",
  "secret": "xos_live_7Hq2wQ1nC8vL0pR4tY6u"
}

Ejemplos de código

curl -X POST "$XOS_BASE_URL/api-keys" \
  -H "Authorization: Bearer $XOS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -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 } = await xos.apiKeys.create({
    "name": "Accounting Sync",
    "service_account_id": "0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f",
    "scopes": [
      "finance"
    ],
    "expires_at": "2026-10-08T14:30:00Z"
  });
response = xos.api_keys.create({"name": "Accounting Sync", "service_account_id": "0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f", "scopes": ["finance"], "expires_at": "2026-10-08T14:30:00Z"})
xos api-keys create --data '{"name":"Accounting Sync","service_account_id":"0192f1e2-7c3a-7b4d-9e8f-1a2b3c4d5e6f","scopes":["finance"],"expires_at":"2026-10-08T14:30:00Z"}'