Skip to main content

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/generate

Authentication (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"
TierRate LimitAuth Required
Free (no key)100 requests/hour per IPNo
API Key1,000 requests/hourAuthorization: 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

ParameterTypeDefaultDescription
data*stringRequired. The value to encode. Max 500 characters.
barcodeFormatstringCODE128Barcode format: CODE128, CODE39, CODE93, EAN13, EAN8, UPC, UPCE, ITF14, ITF, MSI, codabar, pharmacode, EAN5, EAN2.
outputFormatstringsvgOutput format: svg or png. PNG requires server canvas support.
widthnumber2Bar width multiplier. Range: 1–4.
heightnumber100Barcode height in pixels. Range: 20–300.
marginnumber10Quiet zone margin in pixels. Range: 0–50.
colorstring#000000Bar color (hex). e.g. %23000000 or 000000.
bgColorstring#FFFFFFBackground color (hex).
displayValuebooleantrueShow human-readable text below the barcode.
textPositionstringbottomText position: bottom or top.
fontFamilystringmonospaceFont for the text: monospace, sans-serif, serif.
fontSizenumber20Font size in pixels. Range: 8–48.
textAlignstringcenterText alignment: center, left, right.
flatbooleanfalseRemove guard bars for flat rendering.
responsestringSet 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/validate

Response

{
  "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 IDNameInputCommon Uses
CODE128Code 128Full ASCIIShipping, logistics, product IDs
CODE39Code 39A-Z, 0-9, specialIndustrial, military, automotive
CODE93Code 93Full ASCIIPostal, logistics
EAN13EAN-1312-13 digitsRetail products, ISBN books
EAN8EAN-87-8 digitsSmall retail products
UPCUPC-A11-12 digitsUS/Canadian retail
UPCEUPC-E6-8 digitsSmall retail items
ITF14ITF-1414 digitsShipping cartons, pallets
ITFITFEven digitsDistribution, warehouse
MSIMSIDigits onlyShelf labeling, inventory
codabarCodabarDigits + specialLibraries, blood banks
pharmacodePharmacode3-131070Pharmaceutical packaging
EAN5EAN-55 digitsBook price supplements
EAN2EAN-22 digitsPeriodical 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 string

HTML 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

CodeMeaningExample
400Bad Request — invalid parameters or barcode value{ "error": "Invalid value for EAN13. Expected pattern: 12-13 digits." }
429Rate Limited — too many requests{ "error": "Rate limit exceeded. Maximum 100 requests per hour." }
500Server 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.

Related Tools