Barcode API Documentation
Generate barcodes programmatically with a simple REST API. Free, no API key required, and CORS-enabled for browser use. 13 barcode formats, SVG output.
Base URL
https://nofolo.com/api/barcodes/generateAuthentication (Optional)
The API works without authentication at 100 requests/hour per IP. For higher limits (1,000 req/hr), create a free API key from your dashboard.
# With API key (1,000 req/hr) curl "https://nofolo.com/api/barcodes/generate?data=5901234123457&barcodeFormat=EAN13" \ -H "Authorization: Bearer nf_live_your_key_here" # Without API key (100 req/hr) curl "https://nofolo.com/api/barcodes/generate?data=HELLO-123&barcodeFormat=CODE128"
| Tier | Rate Limit | Auth Required |
|---|---|---|
| Free (no key) | 100 requests/hour per IP | No |
| API Key | 1,000 requests/hour | Authorization: Bearer nf_live_... |
GETGenerate Barcode
Generate a barcode image by passing parameters as query strings. Returns an SVG image by default.
GET /api/barcodes/generate?data=5901234123457&barcodeFormat=EAN13&height=80
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| data* | string | — | Required. The value to encode. Max 500 characters. |
| barcodeFormat | string | CODE128 | Barcode format: CODE128, CODE39, CODE93, EAN13, EAN8, UPC, UPCE, ITF14, ITF, MSI, codabar, pharmacode, EAN5, EAN2. |
| outputFormat | string | svg | Output format: svg or png. PNG requires server canvas support. |
| width | number | 2 | Bar width multiplier. Range: 1–4. |
| height | number | 100 | Barcode height in pixels. Range: 20–300. |
| margin | number | 10 | Quiet zone margin in pixels. Range: 0–50. |
| color | string | #000000 | Bar color (hex). e.g. %23000000 or 000000. |
| bgColor | string | #FFFFFF | Background color (hex). |
| displayValue | boolean | true | Show human-readable text below the barcode. |
| textPosition | string | bottom | Text position: bottom or top. |
| fontFamily | string | monospace | Font for the text: monospace, sans-serif, serif. |
| fontSize | number | 20 | Font size in pixels. Range: 8–48. |
| textAlign | string | center | Text alignment: center, left, right. |
| flat | boolean | false | Remove guard bars for flat rendering. |
| response | string | — | Set to json to return a JSON object with SVG string and data URL. |
POSTGenerate Barcode (JSON)
Send a JSON body for more complex configurations. Always returns a JSON response with the SVG string and a data URL.
POST /api/barcodes/generate
Content-Type: application/json
{
"data": "5901234123457",
"barcodeFormat": "EAN13",
"height": 80,
"color": "#1F4E79",
"displayValue": true
}Response
{
"data": "data:image/svg+xml;base64,PHN2ZyB3aWR0...",
"svg": "<svg width="234px" height="122px"...>...</svg>",
"barcodeFormat": "EAN13",
"outputFormat": "svg",
"value": "5901234123457"
}GET / POSTValidate Barcode
Validate a barcode value against a format without generating an image. Returns validation status, format information, and check digit (for EAN/UPC).
https://nofolo.com/api/barcodes/validate# GET — validate via query string
GET /api/barcodes/validate?data=5901234123457&barcodeFormat=EAN13
# POST — validate via JSON body
POST /api/barcodes/validate
{ "data": "5901234123457", "barcodeFormat": "EAN13" }
# GET — list all supported formats (no data parameter)
GET /api/barcodes/validateResponse
{
"valid": true,
"message": "Valid EAN13 barcode",
"value": "5901234123457",
"barcodeFormat": "EAN13",
"formatInfo": {
"name": "EAN-13",
"description": "International standard for retail product identification",
"pattern": "12-13 digits (check digit auto-calculated if 12)",
"maxLength": 13,
"commonUses": ["Retail products worldwide", "ISBN books", "Point of sale"]
},
"checkDigit": "7"
}Supported Barcode Formats
| Format ID | Name | Input | Common Uses |
|---|---|---|---|
| CODE128 | Code 128 | Full ASCII | Shipping, logistics, product IDs |
| CODE39 | Code 39 | A-Z, 0-9, special | Industrial, military, automotive |
| CODE93 | Code 93 | Full ASCII | Postal, logistics |
| EAN13 | EAN-13 | 12-13 digits | Retail products, ISBN books |
| EAN8 | EAN-8 | 7-8 digits | Small retail products |
| UPC | UPC-A | 11-12 digits | US/Canadian retail |
| UPCE | UPC-E | 6-8 digits | Small retail items |
| ITF14 | ITF-14 | 14 digits | Shipping cartons, pallets |
| ITF | ITF | Even digits | Distribution, warehouse |
| MSI | MSI | Digits only | Shelf labeling, inventory |
| codabar | Codabar | Digits + special | Libraries, blood banks |
| pharmacode | Pharmacode | 3-131070 | Pharmaceutical packaging |
| EAN5 | EAN-5 | 5 digits | Book price supplements |
| EAN2 | EAN-2 | 2 digits | Periodical issue numbers |
Code Examples
cURL
# Generate an EAN-13 barcode as SVG curl "https://nofolo.com/api/barcodes/generate?data=5901234123457&barcodeFormat=EAN13" \ -o barcode.svg # Generate a Code 128 barcode with custom styling curl "https://nofolo.com/api/barcodes/generate?data=SHIP-2024-001&barcodeFormat=CODE128&height=80&color=%231F4E79" \ -o shipping-label.svg # Validate a barcode value curl "https://nofolo.com/api/barcodes/validate?data=5901234123457&barcodeFormat=EAN13"
JavaScript (fetch)
// Generate barcode and get SVG + data URL
const response = await fetch('https://nofolo.com/api/barcodes/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
data: '5901234123457',
barcodeFormat: 'EAN13',
height: 80,
displayValue: true,
}),
});
const result = await response.json();
console.log(result.svg); // Raw SVG string
console.log(result.data); // data:image/svg+xml;base64,...
// Validate before generating
const validation = await fetch(
'https://nofolo.com/api/barcodes/validate?data=590123412345&barcodeFormat=EAN13'
).then(r => r.json());
console.log(validation.valid); // true
console.log(validation.checkDigit); // "7"Python (requests)
import requests
# Generate barcode as SVG file
response = requests.get(
"https://nofolo.com/api/barcodes/generate",
params={
"data": "5901234123457",
"barcodeFormat": "EAN13",
"height": 80,
}
)
with open("barcode.svg", "w") as f:
f.write(response.text)
# POST with JSON body
response = requests.post(
"https://nofolo.com/api/barcodes/generate",
json={
"data": "ITEM-001",
"barcodeFormat": "CODE128",
"height": 60,
"color": "#1F4E79",
}
)
result = response.json()
print(result["svg"]) # SVG stringHTML Embed
<!-- Embed barcode directly in an img tag --> <img src="https://nofolo.com/api/barcodes/generate?data=5901234123457&barcodeFormat=EAN13&height=60" alt="EAN-13 barcode" width="200" /> <!-- Code 128 shipping barcode --> <img src="https://nofolo.com/api/barcodes/generate?data=SHIP-2024-001&barcodeFormat=CODE128&height=80" alt="Shipping barcode" />
Error Codes
| Code | Meaning | Example |
|---|---|---|
| 400 | Bad Request — invalid parameters or barcode value | { "error": "Invalid value for EAN13. Expected pattern: 12-13 digits." } |
| 429 | Rate Limited — too many requests | { "error": "Rate limit exceeded. Maximum 100 requests per hour." } |
| 500 | Server Error — unexpected failure | { "error": "Failed to generate barcode" } |
Rate Limiting
Rate limits are enforced per IP address (or per API key if authenticated). The API returns rate limit headers with every response:
X-RateLimit-Limit: 100 # Maximum requests per hour X-RateLimit-Remaining: 95 # Requests remaining in window Retry-After: 3600 # Seconds until window resets (only on 429)
FAQ
Is the Barcode API free?
Yes. The API is free at 100 requests per hour per IP. Create a free API key for 1,000 requests per hour.
Do I need an API key?
No. The API works without authentication. An API key is only needed for higher rate limits.
Can I use this in production?
Yes. The API is production-ready with CORS enabled for browser use. Barcodes are cached for 24 hours at the CDN edge.
What output formats are supported?
SVG is the primary output format and is infinitely scalable. PNG support depends on server canvas availability.
Can I use the API to generate barcodes for commercial products?
Yes. There are no restrictions on commercial use. The generated barcodes are yours to use however you need.
How do I validate a barcode before generating it?
Use the /api/barcodes/validate endpoint to check if a value is valid for a given format before generating.