API Documentation

Getting Started

Generate your first barcode in three steps:

  1. Create an account at the Barcoding dashboard to get your API key.
  2. Make a request to the generation endpoint with your barcode data.
  3. Receive your barcode as a PNG or SVG image in the response.

Your API key is available immediately after signup. The free tier includes 500 generations per month with no credit card required.

Quick Example

```bash curl -X POST https://api.barcoding.io/generate \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"type": "qr", "data": "https://example.com"}' ```

The response is the barcode image with the appropriate Content-Type header (image/png or image/svg+xml).


Authentication

All API requests require an API key passed in the Authorization header using the Bearer scheme.

Authorization: Bearer YOUR_API_KEY

API keys can be created and managed from the dashboard. Each account supports multiple API keys with custom labels. Keys can be revoked at any time.

Key format: API keys are prefixed with brc_. The full key is shown once at creation — store it securely.

Requests without a valid API key receive a 401 Unauthorized response:

{
  "code": "unauthorized",
  "error": "a valid API key is required in the Authorization header"
}

Generate a Barcode

POST /generate

Send a JSON payload with the barcode type and data. The response is the barcode image.

Request Body

ParameterTypeRequiredDescription
typestringYesBarcode symbology: code128, ean13, upca, qr
datastringYesThe content to encode
formatstringNoOutput format: png (default) or svg (Starter plan)
fg_colorstringNoForeground color as hex value. Default: #000000
bg_colorstringNoBackground color as hex value. Default: #FFFFFF
error_correctionstringNoQR only: L, M (default), Q, H (also accepts low, medium, quartile, high)

Example Request

```bash curl -X POST https://api.barcoding.io/generate \ -H "Authorization: Bearer brc_abc123" \ -H "Content-Type: application/json" \ -d '{ "type": "ean13", "data": "4006381333931", "format": "png" }' ```

Response

On success, the response body is the barcode image with the corresponding Content-Type header:

  • PNG: Content-Type: image/png
  • SVG: Content-Type: image/svg+xml

To receive a JSON response with a base64-encoded image instead, set the Accept header to application/json:

{
  "image": "iVBORw0KGgo...",
  "format": "png",
  "type": "ean13",
  "data": "4006381333931",
  "width_px": 264,
  "height_px": 180
}

Validate Data

POST /validate

Check whether input data is valid for a given barcode type without generating an image. Useful for pre-validating user input.

Request Body

ParameterTypeRequiredDescription
typestringYesBarcode symbology: code128, ean13, upca, qr
datastringYesThe content to validate

Example

```bash curl -X POST https://api.barcoding.io/validate \ -H "Authorization: Bearer brc_abc123" \ -H "Content-Type: application/json" \ -d '{"type": "ean13", "data": "400638133393"}' ```

Response

{
  "valid": true,
  "type": "ean13",
  "data": "4006381333931",
  "check_digit": "1"
}

If the data is invalid:

{
  "valid": false,
  "type": "ean13",
  "data": "12345",
  "code": "invalid_data_length",
  "error": "data length is invalid for the requested barcode type"
}

Barcode Types

Code 128

A high-density 1D barcode supporting the full ASCII character set. Commonly used for shipping labels, logistics, and general-purpose labeling.

  • Valid data: ASCII characters (0-127)
  • Length: 1 to 80 characters (recommended maximum)
  • Check digit: Automatically calculated

The encoder selects the optimal character set (A, B, or C) to minimize barcode width. Character set C is used for runs of digits.

EAN-13

The international standard for retail product identification. Used worldwide on consumer products.

  • Valid data: 12 or 13 digits
  • With 12 digits: The check digit is calculated automatically
  • With 13 digits: The check digit is verified against the input

Leading zeros are significant (e.g., country code 001 is different from 01).

UPC-A

The North American standard for retail product identification. A subset of EAN-13.

  • Valid data: 11 or 12 digits
  • With 11 digits: The check digit is calculated automatically
  • With 12 digits: The check digit is verified against the input

QR Code

A 2D barcode capable of encoding text, URLs, and binary data. Used for marketing, payments, authentication, and general-purpose linking.

  • Valid data: Up to 2,953 bytes (depending on error correction level)
  • Error correction levels:
LevelRecovery CapacityBest For
L (or low)~7%Maximum data capacity
M (or medium)~15%General purpose (default)
Q (or quartile)~25%Industrial environments
H (or high)~30%Harsh conditions or small print

The encoder automatically selects the optimal QR version (size) based on the data length and error correction level.


Configuration Options

Output Format

FormatContent-TypeAvailabilityNotes
pngimage/pngAll plansRaster output
svgimage/svg+xmlStarter planVector output, infinitely scalable

Colors

Foreground (fg_color) and background (bg_color) accept 6-digit hex values with a # prefix:

{
  "fg_color": "#1a1a1a",
  "bg_color": "#ffffff"
}

Ensure sufficient contrast between foreground and background for reliable scanning.


Rate Limiting

Each plan has a per-minute request limit:

PlanLimit
Free10 requests/minute
Starter60 requests/minute

Every API response includes rate limit headers:

X-RateLimit-Limit: 60
X-RateLimit-Remaining: 58
X-RateLimit-Reset: 1707782400

When the limit is exceeded, the API returns 429 Too Many Requests:

{
  "code": "rate_limited",
  "error": "rate limit exceeded, try again later"
}

Error Handling

All errors return a consistent JSON structure with an HTTP status code, a machine-readable error code, and a human-readable message.

Error Response Format

{
  "code": "invalid_check_digit",
  "error": "the check digit is incorrect for the provided data"
}

Error Codes

HTTP StatusError CodeDescription
400type_requiredMissing barcode type
400unsupported_typeUnsupported barcode type
400data_requiredMissing or empty data field
400invalid_dataData contains invalid characters for the requested type
400invalid_data_lengthData length outside allowed range
400invalid_check_digitProvided check digit does not match
400data_too_longData exceeds maximum capacity
400invalid_colorInvalid hex color value
400invalid_ec_levelInvalid QR error correction level
400unsupported_formatUnsupported output format
400invalid_payloadRequest body is not valid JSON
401unauthorizedMissing or invalid API key
429rate_limitedToo many requests
429quota_exceededMonthly generation limit reached
500internal_server_errorServer error — contact support

Examples

curl

```bash # Generate a QR code curl -X POST https://api.barcoding.io/generate \ -H "Authorization: Bearer brc_abc123" \ -H "Content-Type: application/json" \ -d '{"type": "qr", "data": "https://example.com"}' \ --output qr.png # Generate a Code 128 barcode curl -X POST https://api.barcoding.io/generate \ -H "Authorization: Bearer brc_abc123" \ -H "Content-Type: application/json" \ -d '{"type": "code128", "data": "SHIP-2024-001"}' \ --output barcode.png ```

Python

```python import requests response = requests.post( "https://api.barcoding.io/generate", headers={"Authorization": "Bearer brc_abc123"}, json={ "type": "ean13", "data": "4006381333931", "format": "png", }, ) with open("barcode.png", "wb") as f: f.write(response.content) ```

JavaScript

```javascript const response = await fetch( "https://api.barcoding.io/generate", { method: "POST", headers: { Authorization: "Bearer brc_abc123", "Content-Type": "application/json", }, body: JSON.stringify({ type: "qr", data: "https://example.com", error_correction: "H", }), } ); const blob = await response.blob(); ```

Go

```go payload := `{"type":"upca","data":"012345678905"}` req, _ := http.NewRequest( "POST", "https://api.barcoding.io/generate", strings.NewReader(payload), ) req.Header.Set("Authorization", "Bearer brc_abc123") req.Header.Set("Content-Type", "application/json") resp, _ := http.DefaultClient.Do(req) defer resp.Body.Close() f, _ := os.Create("barcode.png") defer f.Close() io.Copy(f, resp.Body) ```