# Barcode Encoder API

> Render Code 128, Code 39, EAN, UPC, ITF-14 and Codabar barcodes as PNG, SVG or JPEG.

Encodes a value as a 1D barcode and returns the image bytes directly, so the URL can be used as an `<img src>` from your own backend, or a JSON envelope with a temporary hosted link when `resp=json` is set. Check digits are verified for EAN and UPC values and computed when you send the number without one.

- **Endpoint:** `GET https://api.zactonz.com/barcode/`
- **Category:** Media
- **Version:** 1
- **Status:** stable
- **Authentication:** `Authorization: Bearer YOUR_API_KEY`
- **Reference page:** https://developers.zactonz.com/apis/barcode-encoder/

## Parameters

Send parameters in the query string.

| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| `content` | string | yes |  | The value to encode. Each symbology has its own alphabet and length, listed under the `type` parameter. |
| `type` | enum | no | `code128` | `code128` (printable ASCII, up to 80 characters), `code39` (digits, capitals and `- . $ / + %`), `code93`, `ean13` (12 digits, or 13 with the check digit), `ean8` (7 or 8 digits), `upca` (11 or 12 digits), `upce` (6 to 8 digits), `itf14` (13 or 14 digits), `codabar` (a start and stop letter A to D around digits). Allowed values: `code128`, `code39`, `code93`, `ean13`, `ean8`, `upca`, `upce`, `itf14`, `codabar`. |
| `format` | enum | no | `png` | `png` (default), `svg` or `jpg`. Allowed values: `png`, `svg`, `jpg`. |
| `scale` | integer | no | `2` | Width of the narrowest bar in pixels, 1 to 10. |
| `height` | integer | no | `60` | Bar height in pixels, 20 to 300. |
| `color` | string | no | `000000` | Bar colour as six hex digits. |
| `bgcolor` | string | no | `ffffff` | Background colour as six hex digits. |
| `resp` | enum | no | `image` | `image` streams the bytes. `json` stores the image for 24 hours and returns its link with the dimensions. Allowed values: `image`, `json`. |

## Example request

```bash
curl "https://api.zactonz.com/barcode/?content=ZCTZ-0042&type=code128&format=png&scale=3&height=60&color=000000&bgcolor=ffffff&resp=image" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Response

OK

| Field | Type | Description |
|---|---|---|
| `status` | integer | `200` on success. |
| `data` | object | The result. |
| `data.barcode` | string | Temporary link to the rendered image. |
| `data.type` | string | Symbology used. |
| `data.content` | string | Value encoded. |
| `data.format` | string | Image format. |
| `data.width` | integer | Pixel width, null for SVG. |
| `data.height` | integer | Pixel height, null for SVG. |
| `data.expires_in` | integer | Seconds the link stays valid. |

```json
{
    "status": 200,
    "data": {
        "barcode": "https://api.zactonz.com/f/?p=barcode%2F20260917%2F87ccac83f320062f1d0e9a41.png&e=1789731200&s=2f7c…",
        "type": "upca",
        "content": "12345678901",
        "format": "png",
        "width": 285,
        "height": 60,
        "expires_in": 86400
    }
}
```

## Status codes

The outcome is reported in the JSON `status` field. General rules: https://developers.zactonz.com/apis/errors.md

| status | Meaning | Description |
|---|---|---|
| `400` | Bad request | `content` is missing, or it does not fit the chosen symbology. The message says which rule failed. |
| `401` | Unauthorized | The Authorization header is missing or the key is not recognised. |
| `403` | Forbidden | The key is not licensed for this product. |
| `429` | Too many requests | The per-minute rate or the plan quota is exhausted. Retry after the seconds given in `Retry-After`. |

## Notes

Images are returned with `Cache-Control: public, max-age=86400`. Hosted links from `resp=json` stay valid for 24 hours.
