API Keys¶
Create Api Key¶
import requests
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'leadr-api-key': 'string',
'authorization': 'string',
'leadr-client-nonce': 'string'
}
r = requests.post('/v1/api-keys', headers = headers)
print(r.json())
const inputBody = '{
"account_id": "string",
"user_id": "string",
"name": "string",
"expires_at": "2019-08-24T14:15:22Z"
}';
const headers = {
'Content-Type':'application/json',
'Accept':'application/json',
'leadr-api-key':'string',
'authorization':'string',
'leadr-client-nonce':'string'
};
fetch('/v1/api-keys',
{
method: 'POST',
body: inputBody,
headers: headers
})
.then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});
POST /v1/api-keys
Create a new API key for an account.
The plain API key is returned only once in this response. Store it securely as it cannot be retrieved later.
For regular users, account_id must match their API key's account. For superadmins, any account_id is accepted.
Returns: CreateAPIKeyResponse with the plain key included.
Raises: 403: User does not have access to the specified account. 404: Account not found.
Body parameter
{
"account_id": "string",
"user_id": "string",
"name": "string",
"expires_at": "2019-08-24T14:15:22Z"
}
Parameters¶
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| account_id | query | any | false | none |
| leadr-api-key | header | any | false | none |
| authorization | header | any | false | none |
| leadr-client-nonce | header | any | false | none |
| body | body | CreateAPIKeyRequest | true | none |
Example responses
201 Response
{
"id": "string",
"name": "string",
"key": "string",
"prefix": "string",
"status": "active",
"expires_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z"
}
Responses¶
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 201 | Created | Successful Response | CreateAPIKeyResponse |
| 422 | Unprocessable Entity | Validation Error | HTTPValidationError |
Success
This operation does not require authentication
List Api Keys¶
import requests
headers = {
'Accept': 'application/json',
'leadr-api-key': 'string',
'authorization': 'string',
'leadr-client-nonce': 'string'
}
r = requests.get('/v1/api-keys', headers = headers)
print(r.json())
const headers = {
'Accept':'application/json',
'leadr-api-key':'string',
'authorization':'string',
'leadr-client-nonce':'string'
};
fetch('/v1/api-keys',
{
method: 'GET',
headers: headers
})
.then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});
GET /v1/api-keys
List API keys for an account with optional filters and pagination.
For regular users, account_id is automatically derived from their API key. For superadmins, account_id is optional - if omitted, returns API keys from all accounts.
Pagination: - Default: 20 items per page, sorted by created_at:desc,id:asc - Custom sort: Use ?sort=name:asc,created_at:desc - Valid sort fields: id, name, created_at, updated_at - Navigation: Use next_cursor/prev_cursor from response
Example: GET /v1/api-keys?account_id=acc_123&status=active&limit=50&sort=name:asc
Args: auth: Authentication context with user info. service: Injected API key service dependency. pagination: Pagination parameters (cursor, limit, sort). account_id: Optional account_id query parameter (superadmins can omit to see all). key_status: Optional status to filter results (active or revoked).
Returns: PaginatedResponse with API keys and pagination metadata.
Raises: 400: Invalid cursor, sort field, or cursor state mismatch. 403: User does not have access to the specified account.
Parameters¶
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| account_id | query | any | false | none |
| status | query | any | false | Filter by status |
| cursor | query | any | false | Pagination cursor for navigating results |
| limit | query | integer | false | Number of items per page (1-100) |
| sort | query | any | false | Sort specification (e.g., 'value:desc,created_at:asc') |
| leadr-api-key | header | any | false | none |
| authorization | header | any | false | none |
| leadr-client-nonce | header | any | false | none |
Example responses
200 Response
{
"data": [
{
"id": "scr_123",
"value": 1000
}
],
"pagination": {
"count": 20,
"has_next": true,
"has_prev": false,
"next_cursor": "eyJwdiI6WzEwMDAsMTIzXX0="
}
}
Responses¶
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK | Successful Response | PaginatedResponse_APIKeyResponse_ |
| 422 | Unprocessable Entity | Validation Error | HTTPValidationError |
Success
This operation does not require authentication
Get Api Key¶
import requests
headers = {
'Accept': 'application/json',
'leadr-api-key': 'string',
'authorization': 'string',
'leadr-client-nonce': 'string'
}
r = requests.get('/v1/api-keys/{key_id}', headers = headers)
print(r.json())
const headers = {
'Accept':'application/json',
'leadr-api-key':'string',
'authorization':'string',
'leadr-client-nonce':'string'
};
fetch('/v1/api-keys/{key_id}',
{
method: 'GET',
headers: headers
})
.then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});
GET /v1/api-keys/{key_id}
Get a single API key by ID.
Args: key_id: The UUID of the API key to retrieve. service: Injected API key service dependency. auth: Authentication context with user info.
Returns: APIKeyResponse with key details (excludes the plain key).
Raises: 403: User does not have access to this API key's account. 404: API key not found.
Parameters¶
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| key_id | path | string | true | none |
| account_id | query | any | false | none |
| leadr-api-key | header | any | false | none |
| authorization | header | any | false | none |
| leadr-client-nonce | header | any | false | none |
Example responses
200 Response
{
"id": "string",
"account_id": "string",
"user_id": "string",
"name": "string",
"prefix": "string",
"status": "active",
"last_used_at": "2019-08-24T14:15:22Z",
"expires_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
Responses¶
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK | Successful Response | APIKeyResponse |
| 422 | Unprocessable Entity | Validation Error | HTTPValidationError |
Success
This operation does not require authentication
Update Api Key¶
import requests
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'leadr-api-key': 'string',
'authorization': 'string',
'leadr-client-nonce': 'string'
}
r = requests.patch('/v1/api-keys/{key_id}', headers = headers)
print(r.json())
const inputBody = '{
"status": "active",
"deleted": true
}';
const headers = {
'Content-Type':'application/json',
'Accept':'application/json',
'leadr-api-key':'string',
'authorization':'string',
'leadr-client-nonce':'string'
};
fetch('/v1/api-keys/{key_id}',
{
method: 'PATCH',
body: inputBody,
headers: headers
})
.then(function(res) {
return res.json();
}).then(function(body) {
console.log(body);
});
PATCH /v1/api-keys/{key_id}
Update an API key.
Currently supports: - Updating status (e.g., to revoke a key) - Soft delete via deleted flag
Args: key_id: The UUID of the API key to update. request: Update request with optional status and deleted fields. service: Injected API key service dependency. auth: Authentication context with user info.
Returns: APIKeyResponse with updated key details.
Raises: 403: User does not have access to this API key's account. 404: API key not found.
Body parameter
{
"status": "active",
"deleted": true
}
Parameters¶
| Name | In | Type | Required | Description |
|---|---|---|---|---|
| key_id | path | string | true | none |
| account_id | query | any | false | none |
| leadr-api-key | header | any | false | none |
| authorization | header | any | false | none |
| leadr-client-nonce | header | any | false | none |
| body | body | UpdateAPIKeyRequest | true | none |
Example responses
200 Response
{
"id": "string",
"account_id": "string",
"user_id": "string",
"name": "string",
"prefix": "string",
"status": "active",
"last_used_at": "2019-08-24T14:15:22Z",
"expires_at": "2019-08-24T14:15:22Z",
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
Responses¶
| Status | Meaning | Description | Schema |
|---|---|---|---|
| 200 | OK | Successful Response | APIKeyResponse |
| 422 | Unprocessable Entity | Validation Error | HTTPValidationError |
Success
This operation does not require authentication