# Get an access token

`POST /v1/auth/token` · [Production]

> Base URL: Sandbox `https://sandbox.zulu.com.co/v1` · Production `https://api.zulutransfer.com/v1`

Issues an OAuth2 access token (`client_credentials` grant) from the client credentials. Requires neither `X-API-Key` nor `Authorization`.

The token is a JWT signed with RS256, sent as `Authorization: Bearer <access_token>` on every other endpoint together with your `X-API-Key`. It expires in `expires_in` seconds (one hour): **reuse it until it expires** and only then request another; do not request a token per call.

## Authentication

No `Authorization` or `X-API-Key`: the credentials go in the body.

## Request

### Body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `client_id` | string | required | Client identifier. In the sandbox, the one of your dashboard credentials; in production, the one zulu hands over through a secure channel. min. 1 characters. |
| `client_secret` | string | required | Client secret. Treat it like a password: never in a frontend or a repository. min. 1 characters. |

## Responses

### 200

Token issued.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `access_token` | string | required | JWT signed with RS256. Send it as `Authorization: Bearer <access_token>`. |
| `token_type` | string | required | Always `Bearer`. Always `"Bearer"`. |
| `expires_in` | integer | required | Seconds the token is valid (3600). Reuse it until it expires; do not request a token per call. |
| `scope` | string | optional | Granted scopes. May be absent. |

### 400

`client_id` or `client_secret` is missing, or the body is not valid JSON.

### 401

Invalid credentials.

### 403

The client is not enabled to use the API.

### 429

Too many token requests. Reuse the current token until it expires.

### 500

Internal error.

## Errors

| HTTP | error | cause | Description |
| --- | --- | --- | --- |
| 400 | `BadRequestApiError` | `error in struct validation` | One or more fields fail their validation. `values` carries one message per field, keyed by its JSON path, naming the Go validator that failed. |
| 400 | `BadRequestApiError` | `invalid json body: %s` | The body is not valid JSON, or a field has the wrong type (a string where a number goes, for example). Answered before the fields are validated. |
| 401 | `access_denied` | `Unauthorized` | The `client_id` or the `client_secret` is not valid. |
| 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). |
| 429 | `too_many_requests` | `Too many requests` | Too many token requests. Reuse the current token until it expires (`expires_in`). |
| 500 | `InternalServerApiError` | `[code:1] unexpected error` | Internal error. On operations that move money, check the state before retrying so the operation is not duplicated. |

## Examples

### Valid credentials

```bash
curl https://sandbox.zulu.com.co/v1/auth/token \
  -H "Content-Type: application/json" \
  -d '{
  "client_id": "YOUR_CLIENT_ID",
  "client_secret": "YOUR_CLIENT_SECRET"
}'
```

**Response 200**

```json
{
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9...",
  "token_type": "Bearer",
  "expires_in": 3600
}
```

### Body without credentials

```bash
curl https://sandbox.zulu.com.co/v1/auth/token \
  -H "Content-Type: application/json" \
  -d '{}'
```

**Response 400**

```json
{
  "error": "BadRequestApiError",
  "cause": "error in struct validation",
  "values": {
    "client_id": "failed validation on the \"required\" tag",
    "client_secret": "failed validation on the \"required\" tag"
  }
}
```

### Wrong secret

```bash
curl https://sandbox.zulu.com.co/v1/auth/token \
  -H "Content-Type: application/json" \
  -d '{
  "client_id": "YOUR_CLIENT_ID",
  "client_secret": "not-the-secret"
}'
```

**Response 401**

```json
{
  "error": "access_denied",
  "error_description": "Unauthorized"
}
```
