# QR Encoder API

> Generate a QR code as PNG, JPG, SVG or text.

Generates a QR code from any text or URL and returns a hosted image, inline SVG markup, or the raw matrix as text. Images are kept at the returned URL, so you can hot-link them directly.

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

## Parameters

Send parameters in the query string.

| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| `content` | string | yes |  | The text or URL to encode. URL-encode it when it contains `&` or `#`. Up to 4000 characters. |
| `format` | enum | no | `png` | `png` (default), `jpg`, `svg`, or `text` for a 0/1 matrix in JSON. Allowed values: `png`, `jpg`, `svg`, `text`. |
| `size` | integer | no | `4` | Pixels per QR module, from `1` to `20`. |
| `accuracy` | enum | no | `normal` | Error-correction level. Higher levels survive more damage but produce denser codes. Allowed values: `low`, `normal`, `good`, `high`. |
| `padding` | integer | no | `2` | Quiet zone around the code in modules, 0 to 20. Default 2. |
| `color` | hex | no | `000000` | Foreground colour as six hex digits, for example `ff6700`, or a decimal RGB integer. Default black. |
| `bgcolor` | hex | no | `FFFFFF` | Background colour as six hex digits, for example `ff6700`, or a decimal RGB integer. Default white. |
| `resp` | enum | no | `json` | `json` returns metadata and the image URL. `image` streams the image bytes directly with the right `Content-Type`. Allowed values: `json`, `image`. |

## Example request

```bash
curl "https://api.zactonz.com/qr/enc/?content=https%3A%2F%2Fzactonz.com&format=png&size=6&accuracy=normal&padding=2&color=000000&bgcolor=FFFFFF&resp=json" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Response

A successful reply wraps the result in `data`.

| Field | Type | Description |
|---|---|---|
| `status` | integer | `200` on success. See status codes below. |
| `data` | object |  |
| `data.qr` | string | Absolute URL of the generated image (`png` and `jpg` formats). |
| `data.text` | string | Inline SVG markup or the text matrix (`svg` and `text` formats only). |
| `data.size` | integer | Module size that was applied. |
| `data.accuracy` | string | Error-correction level as a single letter: `L`, `M`, `Q` or `H`. |
| `data.format` | string | Output format that was applied. |

```json
{
    "status": 200,
    "data": {
        "qr": "https://api.zactonz.com/qr/enc/i/qDB76_184XsQzKpYx4e.png",
        "size": 6,
        "accuracy": "M",
        "format": "png"
    }
}
```

## Status codes

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

| status | Meaning | Description |
|---|---|---|
| `200` | OK | The code was generated. |
| `400` | Missing content | `content` was empty or absent. `data` carries the message. |
| `500` | Encoding failed | The encoder could not build the matrix. Shorten the content or lower `accuracy`. |

## Notes

The endpoint sends `Access-Control-Allow-Origin: *`. Call it from your backend all the same, so your API key never reaches the browser.

With `format=svg` or `format=text` the markup is returned inline in `data.text` instead of a hosted file. With `resp=image` the image bytes are streamed directly, which makes the URL usable as an `<img src>`.
