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.
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:
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.
Create API Key
From your profile page, proceed to the "API Keys" section and create a key by filling in a name you prefer.
"QR generator bot" or "My Label Service"
Save Your Credentials
Click on "Create API Key" to generate your credentials, then immediately copy and save both the API Key and Secret.
Your secret key will only be displayed once! Copy it immediately and store it securely. You won't be able to see it again.
Never share your API keys publicly or commit them to version control. Treat them like passwords โ regenerate immediately if compromised.
20 requests per minute per API key. Check your dashboard for current usage and limits.
Endpoints
GET /qr/healthPOST /qr/generatePOST /qr/generate/batchHealth Check
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
Generate a QR code or linear barcode. Send the request as JSON with Content-Type: application/json.
JSON Parameters
| Field | Type | Default | Description |
|---|---|---|---|
type | string | qrcode | Code type โ qrcode or a linear barcode: code128, ean13, upca, ean8, itf, itf14, code39 |
data | string | โ | Content to encode (required) |
output | string | png | Output format โ png, svg, or base64 |
scale | int | 10 | QR pixel scale (QR only) |
border | int | 4 | QR quiet-zone border size (QR only) |
eclevel | string | M | QR error-correction level โ L, M, Q, H (QR only) |
dark | string | #000000 | Foreground color hex (QR only) |
light | string | null | Background color hex, transparent when omitted (QR only) |
module_width | float | 0.2 | Barcode module width in mm (linear only) |
module_height | float | 50 | Barcode module height in mm (linear only) |
font_size | int | 10 | Human-readable text font size (linear only) |
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
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
| Field | Type | Description |
|---|---|---|
items | array | List 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.
| Field | Type | Default | Description |
|---|---|---|---|
filename | string | code_{i}.png | File name inside the ZIP archive |
type | string | qrcode | Code type for this item |
data | string | โ | Content to encode |
output | string | png | Output 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
| Code | Meaning |
|---|---|
200 | Success โ image/zip bytes or base64 JSON |
400 | Bad request / missing JSON / invalid code type / invalid output format / invalid data / too many batch items |
401 | Invalid or missing API key/secret |
413 | Data too long (max 2000 characters) |
429 | Rate limit exceeded |
500 | Internal server error / generation failed / backend library unavailable |