# Withdraw COP balance

`POST /v1/transfer` · [Production]

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

Withdraws COP balance to a bank account in Colombia, your own or a third party's.

**Balance holder.** Comes from the access token: the withdrawal is debited from the COP account of your credentials' user. It is never sent in the body.

**Beneficiary.** Identified by document type and number. It may be the holder itself (one of its accounts) or a third party:

- If already registered, it must be verified and its name must match the one sent (format, accents and order are tolerated).
- If not registered, it is registered with the data sent (names or company name).
- If the bank account is not registered for the beneficiary, it is registered.

**Payout method.** zulu picks how the money goes out and reports it in `method`:

- `BRE_B`: when `breBKey` is sent and the amount is within the Bre-B maximum (12,110,000 COP).
- `ACH`: online transfer, when the beneficiary's bank (`bankCode`) is known and supported, the amount is in whole pesos and within the current caps (`GET /v1/limits`).
- `MANUAL`: in any other case, or when the online transfer could not go out. The withdrawal stays in progress and zulu pays it through the traditional channel; it is not an error.

**Balance.** The amount (plus the dispersion fee, when one applies) is debited from the COP balance when the withdrawal is created. If the balance is not enough, the withdrawal is refused and nothing is recorded.

**Statuses.** `status` uses the same vocabulary in every response and webhook:

| Status | Meaning |
|---|---|
| `CREATED` | Withdrawal created; the Bre-B transfer is in flight. |
| `IN_PROGRESS` | Withdrawal being paid (ACH or manual). |
| `SENT` | The money was sent to the beneficiary's bank. |
| `COMPLETED` | Withdrawal completed. |
| `REJECTED` | Withdrawal rejected. |

**Retries.** Every call creates a new withdrawal. On a 5xx or a timeout, do not retry blindly: check its status before sending it again so the payment is not duplicated. In the sandbox you can send `Idempotency-Key` (coming to production).

## Authentication

`Authorization: Bearer <access_token>` (401 when missing or expired) and `X-API-Key` (403 when missing or not matching).

## Request

### Headers

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string | optional | Idempotency key (up to 255 characters), valid for 24 hours per workspace. Repeating the call with the same key and body returns the original response with `Idempotent-Replayed: true`; a different body answers 422 and, while the first call is still running, 409. Production ignores it today: every call creates a new resource. max. 255 characters. [Sandbox · coming soon] |

### Body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `amount` | number | required | COP amount to withdraw, greater than 0. To go out by online ACH it must be in whole pesos; it is rounded to cents. > 0. |
| `note` | string | optional | Free-text comment recorded on the withdrawal. |
| `destination` | object | required | Beneficiary of the withdrawal and the account the money goes to. If already registered, it must be verified and its name must match the one sent (format, accents and order are tolerated); otherwise it is registered with this data. |
| `destination.entityType` | string | required | Beneficiary type. Values: `person` (Natural person (an individual).), `company` (Company (legal entity).). |
| `destination.documentType` | string | required | Beneficiary document type (for example `CC`, `CE`, `PPT`, `PAS` or `NIT`; `GET /v1/document-types`). min. 1 characters. |
| `destination.documentNumber` | string | required | Document number. For companies the NIT is accepted with or without its check digit. min. 1 characters. |
| `destination.firstName` | string | optional | First name(s). Required when `entityType` is `person`. |
| `destination.middleName` | string | optional | Middle name. |
| `destination.lastName` | string | optional | Last name. Required when `entityType` is `person`. |
| `destination.secondLastName` | string | optional | Second last name. |
| `destination.companyName` | string | optional | Company name. Required when `entityType` is `company`. |
| `destination.bankAccount` | object | required | Colombian (COP) bank account of the beneficiary. |
| `destination.bankAccount.bankCode` | string | optional | Bank code (4-digit ACH code, `GET /v1/banks`). Required for the withdrawal to go out by ACH; Bre-B and manual payment do not need it. When omitted and the account is not registered with its bank in zulu, a withdrawal without `breBKey` stays `MANUAL`. |
| `destination.bankAccount.accountType` | string | required | Account type. `savings`/`saving` mean `ahorros` and `checking` means `corriente`. Values: `ahorros` (Savings account.), `corriente` (Checking account.), `savings` (Alias of `ahorros`.), `saving` (Alias of `ahorros`.), `checking` (Alias of `corriente`.). |
| `destination.bankAccount.accountNumber` | string | required | Account number. Leading zeros are significant. min. 1 characters. |
| `destination.breBKey` | object | optional | Bre-B key of the account sent in `bankAccount`. Optional: when sent and the amount is within the Bre-B maximum, the withdrawal goes out by Bre-B. The key's account number and type are taken from `bankAccount`, so it must be the account the key points to. When sent, all of its fields are required. Get all four with `GET /v1/bre-b/keys/{key}`. |
| `destination.breBKey.key` | string | required | The Bre-B key. min. 1 characters. |
| `destination.breBKey.keyType` | string | required | Key type. The public vocabulary (`ALPHA`, `PHONE`, `EMAIL`, `DOCUMENT`, `MERCHANT`) and GOU's codes (`1` document … `5` merchant) are accepted; `resolveBreBKey` returns it ready to send. min. 1 characters. |
| `destination.breBKey.bankOrgId` | string | required | Tax id (NIT) of the key's bank. min. 1 characters. |
| `destination.breBKey.bankCamera` | string | required | Clearing house of the key. min. 1 characters. |

## Responses

### 201

Withdrawal created.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `transactionId` | string | required | Identifier of the withdrawal in zulu (the order id). An alphanumeric code, not a UUID; in the sandbox it starts with `SBX-`. |
| `status` | string | required | Withdrawal status. Values: `CREATED` (Created. For a Bre-B withdrawal, the transfer is in flight.), `IN_PROGRESS` (In progress: the withdrawal is being paid (ACH or manual) or the conversion awaits settlement.), `SENT` (The money was sent to the beneficiary's bank. Withdrawals only (never FX).), `COMPLETED` (Completed.), `REJECTED` (Rejected. The sandbox reverses the debit automatically; in production operations reverses it.). |
| `method` | string | required | How the money is sent. Values: `BRE_B` (Bre-B: `breBKey` was sent and the amount is within the Bre-B maximum.), `ACH` (Online ACH: a bank with an ACH code, whole pesos and within the current caps.), `MANUAL` (Manual payment: in any other case, or when the online transfer could not go out. Not an error.). |

### 400

Invalid body or missing fields (including those of `breBKey` when it is sent).

### 401

The access token is missing, invalid or expired.

### 403

The `X-API-Key` is not valid (gateway), or the user of the credentials is not verified.

### 409

Conflict with the current state.

### 422

The operation can not be processed; nothing is recorded.

### 429

Too many requests: wait the seconds in `Retry-After`.

### 500

Internal error. Check the withdrawal's status before retrying.

## 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 | — | `Unauthorized` | The `Authorization: Bearer <access_token>` header is missing, or the token is invalid or expired. |
| 403 | — | `Forbidden` | The `X-API-Key` is missing, unknown, revoked or does not belong to the credentials of the token. |
| 403 | `ForbiddenApiError` | `the user is not verified` | The user behind the credentials is not verified. In the sandbox: the workspace "verified" setting. |
| 409 | `ResourceConflictApiError` | `idempotency key "%s" is still being processed` | Another call with the same `Idempotency-Key` is still running. Retry in a few seconds to receive its response. |
| 422 | `UnprocessableEntityApiError` | `idempotency key "%s" was used with a different request` | The `Idempotency-Key` was already used in the last 24 hours with a different body or operation. Use a new key for every distinct operation. |
| 422 | `UnprocessableEntityApiError` | `the user does not have an entity to withdraw from` | The user has no entity to withdraw from. |
| 422 | `UnprocessableEntityApiError` | `the beneficiary with document "%s" is not verified` | The beneficiary registered with that document is not verified. Test data: document `1111111111`. |
| 422 | `UnprocessableEntityApiError` | `the name does not match the beneficiary registered with document "%s"` | The name sent shares no word with the registered beneficiary's (format, accents and order are tolerated). Test data: document `2222222222`, registered as "Ana Pérez". |
| 422 | `UnprocessableEntityApiError` | `insufficient COP balance to withdraw %.2f` | The COP balance does not cover the amount plus the dispersion fee. The figure in the message is that sum. |
| 422 | `UnprocessableEntityApiError` | `the user does not have a COP balance account` | The user has no COP balance account. In the sandbox: the workspace "COP account" setting. |
| 422 | `UnprocessableEntityApiError` | `bank with code "%s" is not supported` | The `bankCode` is not an available bank (see `GET /v1/banks`). Test data: `9999`. |
| 422 | `UnprocessableEntityApiError` | `account type "%s" is not supported` | Unsupported account type. Body validation stops it first (400), so in practice it does not appear. |
| 422 | `UnprocessableEntityApiError` | `document type "%s" is not supported` | The `documentType` of a beneficiary being registered is not in the catalog (`GET /v1/document-types`) or does not apply to its entity type (`NIT` is for companies). It is checked on registration, like the bank; an already registered beneficiary keeps its document. |
| 422 | `UnprocessableEntityApiError` | `destination field "%s" is not valid` | A value being registered can not be stored: the account must have 1 to 20 digits (spaces and hyphens are ignored), the document 1 to 20 characters, and names can not be blank (up to 80 characters; the company name up to 200). The message names the field. |
| 429 | — | `Too Many Requests` | You exceeded the request limit of your credentials. Wait the seconds in `Retry-After`. |
| 500 | `InternalServerApiError` | `[code:1] unexpected error` | Internal error. On operations that move money, check the state before retrying so the operation is not duplicated. |
| 500 | `InternalServerApiError` | `unexpected error %s` | The withdrawal failed at an internal step. Check the withdrawal before retrying so the payment is not duplicated. |

## Examples

### A person's bank account (ACH)

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 150000,
  "note": "Pago factura 1234",
  "destination": {
    "entityType": "person",
    "documentType": "CC",
    "documentNumber": "1020304050",
    "firstName": "Luis",
    "lastName": "Gómez",
    "bankAccount": {
      "bankCode": "0007",
      "accountType": "ahorros",
      "accountNumber": "0012345678"
    }
  }
}'
```

**Response 201**

```json
{
  "transactionId": "SBX-OR-NPTRFI261124K7Q2M9-X4",
  "status": "IN_PROGRESS",
  "method": "ACH"
}
```

### A person's Bre-B key

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 50000,
  "destination": {
    "entityType": "person",
    "documentType": "CC",
    "documentNumber": "1020304050",
    "firstName": "Luis",
    "lastName": "Gómez",
    "bankAccount": {
      "bankCode": "0007",
      "accountType": "ahorros",
      "accountNumber": "0012345678"
    },
    "breBKey": {
      "key": "@luisgomez",
      "keyType": "ALPHA",
      "bankOrgId": "890903938",
      "bankCamera": "TFY"
    }
  }
}'
```

**Response 201**

```json
{
  "transactionId": "SBX-OR-NPTRFI2611243HWD8T-6P",
  "status": "CREATED",
  "method": "BRE_B"
}
```

### A company's bank account

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 2500000,
  "destination": {
    "entityType": "company",
    "documentType": "NIT",
    "documentNumber": "900123456",
    "companyName": "Acme S.A.S.",
    "bankAccount": {
      "bankCode": "0051",
      "accountType": "corriente",
      "accountNumber": "4567890123"
    }
  }
}'
```

**Response 201**

```json
{
  "transactionId": "SBX-OR-NPTRFI261124M2ZK4R-Q8",
  "status": "IN_PROGRESS",
  "method": "ACH"
}
```

### An amount with cents: manual payment

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 150000.5,
  "destination": {
    "entityType": "person",
    "documentType": "CC",
    "documentNumber": "1020304050",
    "firstName": "Luis",
    "lastName": "Gómez",
    "bankAccount": {
      "bankCode": "0007",
      "accountType": "ahorros",
      "accountNumber": "0012345678"
    }
  }
}'
```

**Response 201**

```json
{
  "transactionId": "SBX-OR-NPTRFI261124T5V8B1-3N",
  "status": "IN_PROGRESS",
  "method": "MANUAL"
}
```

### A Bre-B transfer that fails (test data `@failbreb`)

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 50000,
  "destination": {
    "entityType": "person",
    "documentType": "CC",
    "documentNumber": "1020304050",
    "firstName": "Luis",
    "lastName": "Gómez",
    "bankAccount": {
      "bankCode": "0007",
      "accountType": "ahorros",
      "accountNumber": "0012345678"
    },
    "breBKey": {
      "key": "@failbreb",
      "keyType": "ALPHA",
      "bankOrgId": "890903938",
      "bankCamera": "TFY"
    }
  }
}'
```

**Response 201**

```json
{
  "transactionId": "SBX-OR-NPTRFI261124C4F7H2-9R",
  "status": "CREATED",
  "method": "MANUAL"
}
```

### Unsupported account type

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 150000,
  "destination": {
    "entityType": "person",
    "documentType": "CC",
    "documentNumber": "1020304050",
    "firstName": "Luis",
    "lastName": "Gómez",
    "bankAccount": {
      "bankCode": "0007",
      "accountType": "cuenta",
      "accountNumber": "0012345678"
    }
  }
}'
```

**Response 400**

```json
{
  "error": "BadRequestApiError",
  "cause": "error in struct validation",
  "values": {
    "destination.bankAccount.accountType": "failed validation on the \"oneof\" tag with value required \"ahorros corriente savings saving checking\""
  }
}
```

### A person without names

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 150000,
  "destination": {
    "entityType": "person",
    "documentType": "CC",
    "documentNumber": "1020304050",
    "bankAccount": {
      "bankCode": "0007",
      "accountType": "ahorros",
      "accountNumber": "0012345678"
    }
  }
}'
```

**Response 400**

```json
{
  "error": "BadRequestApiError",
  "cause": "error in struct validation",
  "values": {
    "destination.firstName": "failed validation on the \"required_if\" tag with value required \"EntityType person\"",
    "destination.lastName": "failed validation on the \"required_if\" tag with value required \"EntityType person\""
  }
}
```

### Amount sent as text

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": "150000",
  "destination": {
    "entityType": "person",
    "documentType": "CC",
    "documentNumber": "1020304050",
    "firstName": "Luis",
    "lastName": "Gómez",
    "bankAccount": {
      "bankCode": "0007",
      "accountType": "ahorros",
      "accountNumber": "0012345678"
    }
  }
}'
```

**Response 400**

```json
{
  "error": "BadRequestApiError",
  "cause": "invalid json body: json: cannot unmarshal string into Go struct field CreateTransferOutRequest.amount of type float64"
}
```

### Unverified user

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 150000,
  "destination": {
    "entityType": "person",
    "documentType": "CC",
    "documentNumber": "1020304050",
    "firstName": "Luis",
    "lastName": "Gómez",
    "bankAccount": {
      "bankCode": "0007",
      "accountType": "ahorros",
      "accountNumber": "0012345678"
    }
  }
}'
```

**Response 403**

```json
{
  "error": "ForbiddenApiError",
  "cause": "the user is not verified"
}
```

### Unverified beneficiary (`1111111111`)

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 150000,
  "destination": {
    "entityType": "person",
    "documentType": "CC",
    "documentNumber": "1111111111",
    "firstName": "Luis",
    "lastName": "Gómez",
    "bankAccount": {
      "bankCode": "0007",
      "accountType": "ahorros",
      "accountNumber": "0012345678"
    }
  }
}'
```

**Response 422**

```json
{
  "error": "UnprocessableEntityApiError",
  "cause": "the beneficiary with document \"1111111111\" is not verified"
}
```

### Name other than the registered one (`2222222222`)

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 150000,
  "destination": {
    "entityType": "person",
    "documentType": "CC",
    "documentNumber": "2222222222",
    "firstName": "Luis",
    "lastName": "Gómez",
    "bankAccount": {
      "bankCode": "0007",
      "accountType": "ahorros",
      "accountNumber": "0012345678"
    }
  }
}'
```

**Response 422**

```json
{
  "error": "UnprocessableEntityApiError",
  "cause": "the name does not match the beneficiary registered with document \"2222222222\""
}
```

### Insufficient balance

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 150000,
  "destination": {
    "entityType": "person",
    "documentType": "CC",
    "documentNumber": "1020304050",
    "firstName": "Luis",
    "lastName": "Gómez",
    "bankAccount": {
      "bankCode": "0007",
      "accountType": "ahorros",
      "accountNumber": "0012345678"
    }
  }
}'
```

**Response 422**

```json
{
  "error": "UnprocessableEntityApiError",
  "cause": "insufficient COP balance to withdraw 150000.00"
}
```

### Unsupported bank (`9999`)

```bash
curl https://sandbox.zulu.com.co/v1/transfer \
  -H "Authorization: Bearer $ZULU_ACCESS_TOKEN" \
  -H "X-API-Key: $ZULU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "amount": 150000,
  "destination": {
    "entityType": "person",
    "documentType": "CC",
    "documentNumber": "1020304050",
    "firstName": "Luis",
    "lastName": "Gómez",
    "bankAccount": {
      "bankCode": "9999",
      "accountType": "ahorros",
      "accountNumber": "0012345678"
    }
  }
}'
```

**Response 422**

```json
{
  "error": "UnprocessableEntityApiError",
  "cause": "bank with code \"9999\" is not supported"
}
```
