Overview
Blnk uses API key authentication to secure access to the API. All authenticated requests must include theX-Blnk-Key header with a valid API key or master key.
Authentication Header
Include your API key in the request header:Your API key or master key for authentication
Secure Mode
Authentication can be enabled or disabled based on your environment configuration:When
secure is set to false, authentication is bypassed. This should only be used in development environments.Authentication Types
Master Key
The master key provides unrestricted access to all API resources and operations. It’s configured in your Blnk server settings.The master secret key configured in your server settings
API Keys
API keys provide granular, scoped access to specific resources and actions. They can be created, listed, and revoked programmatically.Key Features:
- Scoped permissions: Limit access to specific resources (ledgers, balances, transactions, etc.)
- Action-based control: Restrict to read, write, or delete operations
- Expiration dates: Set expiry times for enhanced security
- Owner tracking: Associate keys with specific users or services
- Automatic metadata injection: Track which API key created resources
Creating API Keys
Create a new API key with specific permissions.Endpoint
Request Body
A descriptive name for the API key
The owner identifier (user ID, service name, etc.)
Array of permission scopes in the format
resource:actionISO 8601 timestamp when the key expires (e.g.,
2024-12-31T23:59:59Z)Example Request
Response
Unique identifier for the API key
The actual API key to use in requests (only returned once)
The name of the API key
The owner identifier
Array of permission scopes
ISO 8601 timestamp of creation
ISO 8601 timestamp of expiration
ISO 8601 timestamp of last usage (null initially)
Permission Scopes
Scopes follow the formatresource:action.
Available Resources
ledgers- Ledger operationsbalances- Balance managementaccounts- Account operationsidentities- Identity managementtransactions- Transaction operationsbalance-monitors- Balance monitoringhooks- Webhook configurationapi-keys- API key managementsearch- Search operationsreconciliation- Reconciliation operationsmetadata- Metadata updatesbackup- Database backup operations*- All resources (wildcard)
Available Actions
read- GET and HEAD requestswrite- POST, PUT, PATCH requestsdelete- DELETE requests*- All actions (wildcard)
Scope Examples
HTTP Method Mapping
| HTTP Method | Required Action |
|---|---|
| GET | read |
| HEAD | read |
| POST | write |
| PUT | write |
| PATCH | write |
| DELETE | delete |
Listing API Keys
Retrieve all API keys for a specific owner.Endpoint
Query Parameters
Filter API keys by owner identifier
Example Request
Response
Returns an array of API key objects (without thekey field):
Revoking API Keys
Revoke an API key to permanently disable it.Endpoint
Parameters
The API key ID to revoke
Owner identifier (must match the key’s owner)
Example Request
Response
Returns HTTP 204 (No Content) on success.Error Responses
API key not found
Unauthorized - owner doesn’t match
Using API Keys
Once created, use the API key in theX-Blnk-Key header:
Automatic Metadata Injection
When an API key is used to create resources (POST requests), Blnk automatically adds metadata to track the creator:Key Expiration and Validation
API keys are validated on every request:- Existence: Key must exist in the database
- Expiration: Current time must be before
expires_at - Status: Key must not be revoked
- Permissions: Key must have appropriate scope for the requested resource and action
Validation Errors
Last Used Tracking
Blnk automatically tracks when each API key was last used. Thelast_used_at timestamp is updated in the background on each successful request.
Best Practices
Public Endpoints
The following endpoints are publicly accessible without authentication:GET /- Server health checkGET /health- Health endpoint