QR & barcode generation

QR & Barcode
API Documentation

Generate QR codes and linear barcodes (Code 128, EAN-13, UPC-A, and more) with full customization โ€” colors, scale, error correction, and output formats โ€” including batch generation over a simple REST API. Built for developers.

Try it now Back to API Hub

Overview

The QR & Barcode API generates QR codes and linear barcodes from JSON requests. QR codes support scale, border, error-correction level, and custom dark/light colors; linear barcodes support module width/height and font size. Output is available as PNG, SVG, or Base64. The batch endpoint produces a ZIP file of up to 50 generated codes in a single call.

Base URL & Authentication

Base URL

Base URL

https://api.chemhub.com/api/v1

Authentication

Include your API credentials in every request header.

Headers

X-API-Key: your_api_key
X-API-Secret: your_secret
Content-Type: application/json

Get API Keys

Follow these steps to obtain your API credentials:

1

Log In to Your Account

Existing Users: Go to /login to access your dashboard

New Users: Visit /register to create your free account first

2

Access Your Profile

Once you log in, click on your profile picture in the top-right corner, then click on "Your profile" from the dropdown menu.

3

Create API Key

From your profile page, proceed to the "API Keys" section and create a key by filling in a name you prefer.

Example name

"QR generator bot" or "My Label Service"

4

Save Your Credentials

Click on "Create API Key" to generate your credentials, then immediately copy and save both the API Key and Secret.

Critical Warning

Your secret key will only be displayed once! Copy it immediately and store it securely. You won't be able to see it again.

Security Notice

Never share your API keys publicly or commit them to version control. Treat them like passwords โ€” regenerate immediately if compromised.

Rate Limits

20 requests per minute per API key. Check your dashboard for current usage and limits.

Endpoints

๐Ÿ’š Health CheckGET /qr/health
๐Ÿ”ณ Generate CodePOST /qr/generate
๐Ÿ—‚๏ธ Batch GeneratePOST /qr/generate/batch

Health Check

GET/qr/health

Health check endpoint to verify the QR & Barcode service status and available generation backends.

Response

Success Response

{
  "success": true,
  "status": "healthy",
  "api_hub_backend": true,
  "segno": true,
  "python_barcode": true,
  "zipfile": true,
  "csp_protection": true
}

Code Examples

Python

import requests

url = "https://api.chemhub.com/api/v1/qr/health"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret"
}

res = requests.get(url, headers=headers)
print(res.json())

cURL

curl -X GET https://api.chemhub.com/api/v1/qr/health \
-H "X-API-Key: your_api_key" \
-H "X-API-Secret: your_secret"

JavaScript

fetch('https://api.chemhub.com/api/v1/qr/health', {
  method: 'GET',
  headers: {
    'X-API-Key': 'your_api_key',
    'X-API-Secret': 'your_secret'
  }
})
.then(res => res.json())
.then(console.log);

Generate QR Code or Barcode

POST/qr/generate

Generate a QR code or linear barcode. Send the request as JSON with Content-Type: application/json.

JSON Parameters

FieldTypeDefaultDescription
typestringqrcodeCode type โ€” qrcode or a linear barcode: code128, ean13, upca, ean8, itf, itf14, code39
datastringโ€”Content to encode (required)
outputstringpngOutput format โ€” png, svg, or base64
scaleint10QR pixel scale (QR only)
borderint4QR quiet-zone border size (QR only)
eclevelstringMQR error-correction level โ€” L, M, Q, H (QR only)
darkstring#000000Foreground color hex (QR only)
lightstringnullBackground color hex, transparent when omitted (QR only)
module_widthfloat0.2Barcode module width in mm (linear only)
module_heightfloat50Barcode module height in mm (linear only)
font_sizeint10Human-readable text font size (linear only)
Response

For png/svg output the endpoint returns the image bytes directly. For base64 output it returns JSON with the encoded data.

cURL Example

cURL

curl -X POST "https://api.chemhub.com/api/v1/qr/generate" \
  -H "X-API-Key: your_api_key" \
  -H "X-API-Secret: your_secret" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "qrcode",
    "data": "https://chemhub.com",
    "output": "png",
    "scale": 10,
    "eclevel": "M"
  }' \
  --output qr.png

Code Examples

Python

import requests

url = "https://api.chemhub.com/api/v1/qr/generate"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret",
    "Content-Type": "application/json"
}

payload = {
    "type": "qrcode",
    "data": "https://chemhub.com",
    "output": "png",
    "scale": 10,
    "border": 4,
    "eclevel": "M",
    "dark": "#000000"
}

response = requests.post(url, headers=headers, json=payload)

if response.status_code == 200:
    with open("qr.png", "wb") as out:
        out.write(response.content)
    print("QR code saved to qr.png")
else:
    print(response.json())

JavaScript

const payload = {
  type: 'qrcode',
  data: 'https://chemhub.com',
  output: 'png',
  scale: 10,
  eclevel: 'M'
};

fetch('https://api.chemhub.com/api/v1/qr/generate', {
  method: 'POST',
  headers: {
    'X-API-Key': 'your_api_key',
    'X-API-Secret': 'your_secret',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(payload)
})
.then(async res => {
  if (res.ok) {
    const blob = await res.blob();
    const url = URL.createObjectURL(blob);
    console.log('QR code URL:', url);
  } else {
    console.log(await res.json());
  }
});

Batch Generate

POST/qr/generate/batch

Generate up to 50 QR codes or barcodes in a single request. Each item in the items array is generated independently and the results are returned as a ZIP archive (qr_barcode_batch.zip).

JSON Parameters

FieldTypeDescription
itemsarrayList of code objects โ€” max 50 items (required)

Item Fields

Each item supports the same fields as POST /qr/generate, plus an optional filename for the archive entry.

FieldTypeDefaultDescription
filenamestringcode_{i}.pngFile name inside the ZIP archive
typestringqrcodeCode type for this item
datastringโ€”Content to encode
outputstringpngOutput format โ€” png or svg (base64 is not supported in batches)

cURL Example

cURL

curl -X POST "https://api.chemhub.com/api/v1/qr/generate/batch" \
  -H "X-API-Key: your_api_key" \
  -H "X-API-Secret: your_secret" \
  -H "Content-Type: application/json" \
  -d '{
    "items": [
      {"type": "qrcode", "data": "https://chemhub.com", "filename": "home.png"},
      {"type": "code128", "data": "ABC-12345", "filename": "sku.png"}
    ]
  }' \
  --output batch.zip

Code Examples

Python

import requests

url = "https://api.chemhub.com/api/v1/qr/generate/batch"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret",
    "Content-Type": "application/json"
}

payload = {
    "items": [
        {"type": "qrcode", "data": "https://chemhub.com", "filename": "home.png"},
        {"type": "code128", "data": "ABC-12345", "filename": "sku.png"}
    ]
}

response = requests.post(url, headers=headers, json=payload)

if response.status_code == 200:
    with open("batch.zip", "wb") as out:
        out.write(response.content)
    print("Batch saved to batch.zip")
else:
    print(response.json())

JavaScript

const payload = {
  items: [
    { type: 'qrcode', data: 'https://chemhub.com', filename: 'home.png' },
    { type: 'code128', data: 'ABC-12345', filename: 'sku.png' }
  ]
};

fetch('https://api.chemhub.com/api/v1/qr/generate/batch', {
  method: 'POST',
  headers: {
    'X-API-Key': 'your_api_key',
    'X-API-Secret': 'your_secret',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify(payload)
})
.then(async res => {
  if (res.ok) {
    const blob = await res.blob();
    const url = URL.createObjectURL(blob);
    console.log('Batch ZIP URL:', url);
  } else {
    console.log(await res.json());
  }
});

Python SDK

Complete Python SDK covering health check, single-code generation, and batch generation.

Complete SDK Class

import requests
import io

BASE_URL = "https://api.chemhub.com/api/v1"
API_KEY = "YOUR_API_KEY"
API_SECRET = "YOUR_API_SECRET"

headers = {
    "X-API-Key": API_KEY,
    "X-API-Secret": API_SECRET
}

# --- Health Check ---
def check_health():
    return requests.get(f"{BASE_URL}/qr/health", headers=headers).json()

# --- Generate a single QR code or barcode ---
def generate_code(code_type="qrcode", data="https://chemhub.com",
                  output="png", output_path="code.png", **options):
    payload = {"type": code_type, "data": data, "output": output}
    payload.update(options)
    response = requests.post(
        f"{BASE_URL}/qr/generate",
        headers=headers,
        json=payload
    )

    if response.status_code == 200:
        if output == "base64":
            result = response.json()
            print("Encoded base64 data:", result.get("base64")[:64], "...")
            return result
        with open(output_path, "wb") as out:
            out.write(response.content)
        print(f"Saved: {output_path}")
        return output_path
    print(f"Error: {response.status_code} - {response.text}")
    return None

# --- Generate a batch of codes (returns a ZIP) ---
def generate_batch(items, output_path="batch.zip"):
    response = requests.post(
        f"{BASE_URL}/qr/generate/batch",
        headers=headers,
        json={"items": items}
    )
    if response.status_code == 200:
        with open(output_path, "wb") as out:
            out.write(response.content)
        print(f"Saved: {output_path}")
        return output_path
    print(f"Error: {response.status_code} - {response.text}")
    return None

# --- Test all endpoints ---
if __name__ == "__main__":
    print("=== QR & BARCODE API TEST ===")

    health = check_health()
    print(f"Health: {health.get('status', 'unknown')}")
    print(f"Segno: {health.get('segno')} | python-barcode: {health.get('python_barcode')}")

    print("\n1. Generating QR code:")
    generate_code(
        code_type="qrcode",
        data="https://chemhub.com",
        output="png",
        output_path="qr.png",
        scale=10,
        eclevel="M"
    )

    print("\n2. Generating Code 128 barcode:")
    generate_code(
        code_type="code128",
        data="ABC-12345",
        output="svg",
        output_path="barcode.svg"
    )

    print("\n3. Batch generation:")
    generate_batch([
        {"type": "qrcode", "data": "https://chemhub.com", "filename": "home.png"},
        {"type": "ean13", "data": "5901234123457", "filename": "sku.png"}
    ])

Errors & Status Codes

Error Response Format

Error Response

{
  "success": false,
  "error": "Invalid code type",
  "message": "Supported types: qrcode, code128, ean13, upca, ean8, itf, itf14, code39"
}

Status Codes

CodeMeaning
200Success โ€” image/zip bytes or base64 JSON
400Bad request / missing JSON / invalid code type / invalid output format / invalid data / too many batch items
401Invalid or missing API key/secret
413Data too long (max 2000 characters)
429Rate limit exceeded
500Internal server error / generation failed / backend library unavailable

Limitations

Max data length: 2000 characters
Rate limit: 20 requests per minute
Batch size: up to 50 items per batch request
QR outputs: PNG, SVG, Base64
Linear barcodes: code128, ean13, upca, ean8, itf, itf14, code39
Batch output: single ZIP archive; base64 not supported in batches