Skip to main content

Get API Key by ID

Retrieves detailed information about a specific API key by its unique identifier. This endpoint returns the full metadata for an API key including configuration, usage statistics, and audit information. Used for API key management and troubleshooting.


Endpoint

Method: GET URL: {{base_url}}/api/v1/api-keys/{keyId}


Authentication

This endpoint uses Bearer Token authentication via a JWT (JSON Web Token). The token must be included in the Authorization header. Requires admin-level permissions.


Headers

HeaderDescriptionRequired
AuthorizationBearer token (JWT) for authenticationYes
acceptSpecifies acceptable response formats (application/json)Yes
x-tenantidUUID identifying the tenant/organizationYes
realmnameThe authentication realm nameNo

Path Parameters

ParameterTypeDescriptionRequired
keyIdstring (UUID)The unique identifier of the API keyYes

Query Parameters

None.


Request Body Schema

Not applicable — this is a GET request with no request body.


Example cURL

curl --request GET \
--url '{{base_url}}/api/v1/api-keys/{{key_id}}' \
--header 'accept: application/json' \
--header 'authorization: Bearer {{access_token}}' \
--header 'x-tenantid: {{tenant_id}}'

Success Response Example

Status Code: 200 OK

{
"success": true,
"message": "API key retrieved successfully",
"data": {
"id": "{{key_id}}",
"name": "Production Integration Key",
"description": "API key for ServiceNow integration",
"prefix": "ak_live_xxxx",
"scopes": [
"ticketing:read",
"ticketing:write",
"users:read"
],
"protocol": "rest",
"ipWhitelist": [
"{{allowed_ip_range_1}}",
"{{allowed_ip_range_2}}"
],
"environment": "live",
"status": "active",
"permissions": {
"ticketing": {
"read": true,
"write": true,
"delete": false,
"admin": false
},
"users": {
"read": true,
"write": false,
"admin": false
},
"catalog": {
"read": false,
"write": false
},
"reports": {
"read": false
}
},
"rateLimit": {
"requestsPerMinute": 100,
"requestsPerHour": 5000,
"requestsPerDay": 50000,
"currentUsage": {
"minuteCount": 12,
"hourCount": 234,
"dayCount": 1542
}
},
"expiresAt": "2026-07-10T12:50:00.000Z",
"isExpired": false,
"daysUntilExpiration": 365,
"usage": {
"totalRequests": 154200,
"successfulRequests": 153890,
"failedRequests": 310,
"lastUsedAt": "2025-07-10T12:55:00.000Z",
"lastUsedFromIp": "{{client_ip}}",
"firstUsedAt": "2025-01-16T08:30:00.000Z",
"averageRequestsPerDay": 856
},
"audit": {
"createdAt": "2025-01-15T10:00:00.000Z",
"createdBy": {
"id": "{{user_id}}",
"name": "{{user_name}}",
"email": "{{user_email}}"
},
"updatedAt": "2025-06-01T14:00:00.000Z",
"updatedBy": {
"id": "{{user_id}}",
"name": "{{user_name}}",
"email": "{{user_email}}"
},
"lastRotatedAt": null,
"rotationCount": 0
},
"tenant": {
"id": "{{tenant_id}}",
"name": "{{tenant_name}}"
}
},
"timestamp": "2025-07-10T13:00:00.000Z"
}

API Key Object Schema

FieldTypeDescription
idstringUnique API key identifier (UUID)
namestringHuman-readable name
descriptionstringDescription of the key's purpose
prefixstringKey prefix for identification (first 12 chars)
scopesarrayList of permission scopes
protocolstringAPI protocol (rest, graphql)
ipWhitelistarrayAllowed IP addresses/CIDR ranges
environmentstringEnvironment type: live or test
statusstringKey status: active, inactive, expired, revoked
permissionsobjectDetailed permission breakdown by resource
rateLimitobjectRate limit configuration and current usage
expiresAtstring|nullISO 8601 expiration timestamp
isExpiredbooleanWhether the key is currently expired
daysUntilExpirationinteger|nullDays remaining until expiration
usageobjectUsage statistics
auditobjectAudit trail information
tenantobjectAssociated tenant information

Usage Statistics Object

FieldTypeDescription
totalRequestsintegerTotal API requests made with this key
successfulRequestsintegerNumber of successful requests (2xx responses)
failedRequestsintegerNumber of failed requests (4xx/5xx responses)
lastUsedAtstring|nullISO 8601 timestamp of last usage
lastUsedFromIpstring|nullIP address of last request
firstUsedAtstring|nullISO 8601 timestamp of first usage
averageRequestsPerDaynumberAverage daily request count

Rate Limit Object

FieldTypeDescription
requestsPerMinuteintegerMaximum requests allowed per minute
requestsPerHourintegerMaximum requests allowed per hour
requestsPerDayintegerMaximum requests allowed per day
currentUsage.minuteCountintegerRequests made in current minute
currentUsage.hourCountintegerRequests made in current hour
currentUsage.dayCountintegerRequests made today

Error Responses

Status CodeErrorDescription
400 Bad RequestInvalid key ID formatThe keyId is not a valid UUID
401 UnauthorizedAuthentication failedBearer token is missing, expired, or invalid
403 ForbiddenInsufficient permissionsUser lacks permission to view this API key
404 Not FoundAPI key not foundNo API key exists with the specified ID
500 Internal Server ErrorServer errorUnexpected server-side error

Example Error Response:

{
"success": false,
"error": {
"code": "API_KEY_NOT_FOUND",
"message": "API key not found",
"details": "No API key exists with ID: {{key_id}}"
},
"timestamp": "2025-07-10T13:00:00.000Z"
}

Notes

  1. Security: The full API key value is never returned. Only the prefix is shown for identification purposes.

  2. UUID Format: The keyId must be a valid UUID. Invalid formats will return a 400 error.

  3. Detailed Permissions: Unlike the list endpoint, this response includes a detailed permissions breakdown showing exactly what resources and actions the key can access.

  4. Rate Limit Monitoring: The rateLimit.currentUsage object shows real-time usage against limits, useful for monitoring and troubleshooting.

  5. Usage Analytics: The usage object provides comprehensive statistics for auditing and identifying usage patterns.

  6. Expiration Info: The isExpired and daysUntilExpiration fields make it easy to identify keys needing renewal.

  7. Audit Trail: The audit object tracks creation, updates, and rotation history for compliance requirements.

  8. Required Roles: Typically requires tenant_admin or api_admin role to view API key details.

  9. Related Endpoints:

    • GET /api-keys — List all API keys
    • POST /api-keys — Create new API key
    • PUT /api-keys/{keyId} — Update API key
    • DELETE /api-keys/{keyId} — Revoke/delete API key
    • POST /api-keys/{keyId}/rotate — Rotate API key
    • POST /api-key/validate — Validate an API key