Barcode Generator API: The Complete Guide

Need to generate barcodes in your application? This guide covers everything you need to know about barcode generation via API, including different barcode formats, customization options, and implementation examples.

What is a Barcode?

A barcode is a visual representation of data using parallel lines (1D) or patterns (2D) that can be read by optical scanners. Barcodes enable fast, accurate data capture and are essential for inventory management, retail, and logistics.

Different barcode formats are optimized for different use cases, from retail products (EAN/UPC) to shipping labels (Code128).

Barcode Formats

Common barcode formats supported:

Code128

High-density barcode supporting all 128 ASCII characters. Ideal for shipping labels and inventory.

Code39

Alphanumeric barcode used in automotive, defense, and healthcare industries.

EAN-13 / EAN-8

European Article Number for retail products. EAN-13 is the international standard.

UPC-A / UPC-E

Universal Product Code used primarily in North America for retail products.

Choosing a Format: Use EAN/UPC for retail products, Code128 for shipping and logistics, and Code39 for industrial applications.

Using the Barcode Generator API

TinyFn provides a simple endpoint to generate barcodes:

API Request
POST https://api.tinyfn.io/v1/generate/barcode
Headers: X-API-Key: your-api-key
Content-Type: application/json

{
  "data": "ABC-12345",
  "format": "code128",
  "width": 300,
  "height": 100
}
Response
{
  "barcode": "data:image/png;base64,iVBORw0KGgo...",
  "format": "code128",
  "data_encoded": "ABC-12345",
  "width": 300,
  "height": 100
}

Parameters

Parameter Type Description
data string Data to encode in barcode (required)
format string Barcode format: code128, code39, ean13, upc-a, etc.
width integer Image width in pixels (default: 200)
height integer Image height in pixels (default: 100)
show_text boolean Display text below barcode (default: true)

Code Examples

JavaScript / Node.js

const response = await fetch('https://api.tinyfn.io/v1/generate/barcode', {
  method: 'POST',
  headers: {
    'X-API-Key': 'your-api-key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({ data: 'ABC-12345', format: 'code128' })
});
const result = await response.json();
// Use result.barcode as image src

Python

import requests

response = requests.post(
    'https://api.tinyfn.io/v1/generate/barcode',
    json={'data': 'ABC-12345', 'format': 'code128'},
    headers={'X-API-Key': 'your-api-key'}
)
result = response.json()
# Save or display result['barcode']

cURL

curl -X POST "https://api.tinyfn.io/v1/generate/barcode" \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"data": "ABC-12345", "format": "code128"}'

Common Use Cases

  • Inventory Management: Generate labels for stock tracking
  • Shipping Labels: Create shipping and tracking barcodes
  • Product Labels: Generate retail product barcodes
  • Asset Tracking: Label equipment and assets
  • Ticketing: Event tickets and access control

Best Practices

  1. Choose correct format: Match barcode format to your industry requirements
  2. Ensure readability: Test barcodes with actual scanners
  3. Include quiet zones: Leave white space around barcodes
  4. Verify data: Validate input data matches format requirements

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "tinyfn-generate": {
      "url": "https://api.tinyfn.io/mcp/generate/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

See all generator tools available via MCP in our Generator MCP Tools for AI Agents guide.

Try the Barcode Generator API

Get your free API key and start generating barcodes in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key