Skip to main content

Create an API key

Mint a new API key on behalf of a user — for example, to set up a SAP or HRIS integration.

POST/api/admin/api-keys 🔒 API key · admin role

Creates a new API key for a user. The plaintext key is returned exactly once in this response — store it securely. The key inherits the target user’s role and organization memberships.

Request body

FieldTypeRequiredDescription
namestringYesHuman-readable label (max 255 chars).
userIdstringYesID of the user the key acts as. Must exist.
expiresInDaysintegerNoDays until expiry. Default 90, range 1–365.

Example request

curl -X POST https://app.talent-ray.com/api/admin/api-keys \
  -H "Authorization: Bearer tr_YOUR_ADMIN_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Karaca SAP nightly sync",
    "userId": "user_abc123",
    "expiresInDays": 30
  }'

Response

200 OK — the key field is shown only here and never again.

{
  "success": true,
  "data": {
    "id": "apikey_xyz789",
    "name": "Karaca SAP nightly sync",
    "key": "tr_aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    "prefix": "tr_",
    "start": "tr_aaaa",
    "expiresAt": "2026-09-03T12:00:00Z",
    "userId": "user_abc123"
  }
}
FieldTypeDescription
idstringThe key’s ID — use it to revoke or audit the key.
keystringThe plaintext key. Shown once.
prefixstringAlways tr_.
startstringFirst characters, for display.
expiresAtstringISO 8601 expiry timestamp.
userIdstringThe owner the key acts as.

Status codes

StatusMeaning
200Key created.
400Validation error (missing name/userId, bad expiresInDays).
401No valid API key.
403Caller is not an admin.
404userId not found.
429Rate limited.