> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tunimobile.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate a voucher

> Sell a voucher: reserve it for this terminal and debit the shop balance.

Reserves a voucher for this terminal, marks it `printed` and **debits the shop balance**. Print the returned data right away, then call [Confirm a printed voucher](https://docs.tunimobile.com/api/vouchers/confirm.md).

> [!WARNING]
>
> Do not retry `printVoucher` automatically after a timeout: each successful call sells a new voucher. Check the [voucher history](https://docs.tunimobile.com/api/vouchers/history.md) first, then use [reprint](https://docs.tunimobile.com/api/vouchers/reprint.md) if the voucher was already generated.

## Headers

**api-key** `string` *required*

The [terminal API key](https://docs.tunimobile.com/basics/terminal-api-key.md).

## Body

**action** `string` *required*

`printVoucher`

**operator** `string` *required*

`tt`, `orange` or `ooredoo`.

**value** `number` *required*

`1` or `5` (TND).

## Response

**id** `integer`

Voucher id. Keep it for [reprint](https://docs.tunimobile.com/api/vouchers/reprint.md) and [confirm reprint](https://docs.tunimobile.com/api/vouchers/confirm-reprint.md).

**cartNumber** `string`

Recharge code to print, grouped by 5 digits.

**serieNumber** `string`

Serial number. Keep it for [confirm](https://docs.tunimobile.com/api/vouchers/confirm.md) and [duplicate](https://docs.tunimobile.com/api/vouchers/duplicate.md).

**operator** `string`

Operator of the voucher.

**value** `number`

Face value in TND.

**expireAt** `string`

Expiry date of the voucher.

**printedAt** `string`

Sale date and time.

**size** `string`

Ticket layout for this terminal.

**logo** `string`

Shop logo (black and white) to print on the ticket.

**barcode** `string | null`

Shop barcode for this operator and value, or `null`.

**footer** `string`

Text to print at the bottom of the ticket.

**operatorLogo** `string`

URL of the operator/value image.

## Errors

| HTTP | `error.details` | Meaning |
| - | - | - |
| `400` | `apiKey not found` | `api-key` header missing |
| `400` | `Terminal not found` | Unknown API key |
| `400` | `Terminal not active` | Terminal disabled by the shop or an admin |
| `400` | `operator not found` | `operator` not in `tt`, `orange`, `ooredoo` |
| `400` | `value not found` | `value` not `1` or `5` |
| `400` | `Solde de la boutique insuffisant` | Balance too low |
| `400` | `Buy price not found` | No price configured for this product. Contact support. |
| `404` | `Voucher not found` | Out of stock for this operator and value |
| `404` | `Session not found` | No session for this terminal. Call [Open / close a sales session](https://docs.tunimobile.com/api/sessions/rotate.md). |
| `404` | `something_went_wrong` | No clean voucher found after several attempts. Try again. |

```bash cURL theme={null}
curl -H "api-key: 6f1c2a9e-4b7d-4e0a-9c55-2d8f3b1a7e10" \
  -H "Content-Type: application/json" \
  -d '{"action":"printVoucher","operator":"orange","value":5}' \
  https://apitest.tunimobile.com/v1/voucher/do_action
```

```json 200 theme={null}
{
  "status": "success",
  "code": 200,
  "message": "OK",
  "data": {
    "id": 987654,
    "cartNumber": "12345 67890 12345",
    "serieNumber": "0012345678",
    "operator": "orange",
    "value": 5,
    "expireAt": "2027-06-30 00:00:00",
    "printedAt": "2026-10-28 10:15:03",
    "size": "standard",
    "logo": "https://api.tunimobile.com/images/avatars_bw/123.png",
    "barcode": "6191234567890",
    "footer": "Powered By TuniMobile.com",
    "operatorLogo": "https://api.tunimobile.com/images/operator/orange_5.jpg"
  }
}
```

```json 400 theme={null}
{
  "status": "error",
  "code": 400,
  "message": "Bad Request",
  "error": { "details": "Solde de la boutique insuffisant" }
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.