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

# Barcodes

> Generating Omneo-authenticated barcodes for embedding in emails, web pages, and digital passes.

The Omneo Barcode service generates barcode images that can be embedded anywhere an `<img>` tag is accepted, emails, web pages, digital wallet passes, and more. Barcodes are authenticated via HMAC to prevent unauthorised generation.

## How it works

1. Decide on your barcode parameters (data, type, dimensions, colours)
2. Generate an HMAC-256 token from your parameters using your Omneo barcode secret
3. Set the barcode service URL as the `src` of an `<img>` tag

```html theme={null}
<img src="https://omneo-barcode-v5r64nnrcq-ts.a.run.app/barcode?data=13924318823&type=code128&padding=0&color=black&bgColor=white&hriFontSize=3&hriMarginTop=1&token=YOUR_TOKEN"/>
```

## Live example

The image below is generated in real time by the Omneo Barcode service using the parameters and token shown in [Authentication](#authentication), view source on this page to see the exact `<img>` tag.

<img src="https://omneo-barcode-v5r64nnrcq-ts.a.run.app/barcode?data=OmneoBarcodes&hriMarginTop=1&hriFontSize=5&padding=0&color=black&bgColor=white&token=191cfc1a96c07c2acd96d6146a1048145160c1560a73a8134188696ee342d827" alt="Live barcode encoding OmneoBarcodes" />

## Authentication

Get your barcode secret from your Omneo administrator. The secret is tenant-specific.

Generate the HMAC-256 token from your parameters string (everything except `&token=...`):

```
Parameters: data=13924318823&padding=0&color=black&bgColor=white&type=code128&hriFontSize=3&hriMarginTop=1&hriFontFamily=Geneva
Secret: 1234
Token: 13628a9b6c8e9e0eb39cf63f5876477dc66fa688622010a6e10c9f2cba4f3f6e
```

The token is only valid for the exact set of parameters used to generate it. Changing any parameter invalidates the token.

## Barcode types

| Type         | Character restrictions   |
| ------------ | ------------------------ |
| `code128`    | Full ASCII               |
| `code39`     | Alphanumeric + `-. $/+%` |
| `ean13`      | 12 numerical digits      |
| `ean8`       | 7 numerical digits       |
| `datamatrix` | No restrictions (2D)     |
| `upc`        | 11 numerical digits      |
| `qr`         | Full Unicode (2D)        |

## Key parameters

| Parameter       | Description                            | Default  |
| --------------- | -------------------------------------- | -------- |
| `data`          | Value to encode                        | Required |
| `type`          | Barcode type (see above)               | Required |
| `token`         | HMAC-256 authentication token          | Required |
| `color`         | Bar colour (hex or named)              | `black`  |
| `bgColor`       | Background colour                      | `white`  |
| `padding`       | Padding in pixels (all sides)          | `0`      |
| `width`         | Image width in pixels                  | `150`    |
| `height`        | Image height in pixels                 | `150`    |
| `barWidth`      | Bar width in pixels (1D only)          | `1`      |
| `barHeight`     | Bar height in pixels (1D only)         | `50`     |
| `hriShow`       | Show human-readable text below barcode | `true`   |
| `hriFontFamily` | Font for human-readable text           | `Geneva` |
| `hriFontSize`   | Font size for human-readable text      | ,        |
| `hriMarginTop`  | Margin between barcode and HRI text    | `0`      |

## Common use case: Loyalty card barcode in email

Generate a barcode with the customer's loyalty card number for inclusion in a welcome email:

```javascript theme={null}
const crypto = require('crypto')

function generateBarcodeUrl(loyaltyCardNumber, secret) {
  const params = `data=${loyaltyCardNumber}&type=code128&padding=4&color=black&bgColor=white&hriShow=true&hriFontSize=3&hriMarginTop=2`
  const token = crypto.createHmac('sha256', secret).update(params).digest('hex')
  return `https://omneo-barcode-v5r64nnrcq-ts.a.run.app/barcode?${params}&token=${token}`
}
```
