Skip to content
developers

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:

  1. An OAuth2 access token you get with your client_id and your client_secret. It travels in Authorization: Bearer <access_token>.
  2. Your API key, which travels in the X-API-Key header.

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

HTTPerrorcauseDescription
401access_deniedUnauthorizedThe client_id or the client_secret is not valid.
401—UnauthorizedThe Authorization: Bearer <access_token> header is missing, or the token is invalid or expired.
403access_deniedClient is not authorized to access this APIThe credentials are valid but the client is not enabled to use the API (revoked credential or suspended workspace).
403—ForbiddenThe X-API-Key is missing, unknown, revoked or does not belong to the credentials of the token.
429too_many_requestsToo many requestsToo many token requests. Reuse the current token until it expires (expires_in).
429—Too Many RequestsYou 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_secret and X-API-Key in 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.