Getting started
Authentication
OAuth2 client_credentials for a one-hour token, and the token plus your X-API-Key on every call.
The API uses two credentials together, the same way in the sandbox and in production:
- An OAuth2 access token you get with your
client_idand yourclient_secret. It travels inAuthorization: Bearer <access_token>. - Your API key, which travels in the
X-API-Keyheader.
Get the token
POST/v1/auth/tokenGet an access tokenProduction
The body is snake_case, as in OAuth2 (client_id, client_secret). It is the only place in the API that is not camelCase.
POST /v1/auth/token
curl https://sandbox.zulu.com.co/v1/auth/token \
-H "Content-Type: application/json" \
-d "{\"client_id\": \"$ZULU_CLIENT_ID\", \"client_secret\": \"$ZULU_CLIENT_SECRET\"}"The token is a JWT, but treat it as an opaque value: do not depend on its contents.
Reuse the token
The token expires in expires_in seconds (3600, one hour). Request a new one only when it is about to expire: requesting one per call can end in 429 too_many_requests. A minimal cache in Node, with ZULU_API_URL pointing at your environment's base URL:
token.js
let cached = null;
export async function accessToken() {
if (cached && cached.expiresAt - 60_000 > Date.now()) return cached.value;
const response = await fetch(`${process.env.ZULU_API_URL}/auth/token`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ client_id: process.env.ZULU_CLIENT_ID, client_secret: process.env.ZULU_CLIENT_SECRET }),
});
if (!response.ok) throw new Error(`zulu token: ${response.status}`);
const body = await response.json();
cached = { value: body.access_token, expiresAt: Date.now() + body.expires_in * 1000 };
return cached.value;
}Call every other endpoint
Every call carries both headers:
cURL
curl https://sandbox.zulu.com.co/v1/balances \
-H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
-H "X-API-Key: $ZULU_API_KEY"The checks run in production's gateway order: first the token (missing or expired, 401 {"message":"Unauthorized"}), then the API key (missing, or another credential's, 403 {"message":"Forbidden"}).
Authentication errors
| HTTP | error | cause | Description |
|---|---|---|---|
| 401 | access_denied | Unauthorized | The client_id or the client_secret is not valid. |
| 401 | — | Unauthorized | The Authorization: Bearer <access_token> header is missing, or the token is invalid or expired. |
| 403 | access_denied | Client is not authorized to access this API | The credentials are valid but the client is not enabled to use the API (revoked credential or suspended workspace). |
| 403 | — | Forbidden | The X-API-Key is missing, unknown, revoked or does not belong to the credentials of the token. |
| 429 | too_many_requests | Too many requests | Too many token requests. Reuse the current token until it expires (expires_in). |
| 429 | — | Too Many Requests | You exceeded the request limit of your credentials. Wait the seconds in Retry-After. |
An unknown client_id and a wrong secret answer the same (401 access_denied), so nobody can find out which clients exist.
Good practices
- Keep
client_secretandX-API-Keyin a secrets manager or in environment variables; never in the repository or the frontend. - Use separate credentials per environment and per service, so you can revoke them one by one from the dashboard.
- If a credential leaks, revoke it: its tokens stop working even before they expire.