Barcode Generator

Barcode Generator API

Utilities

Create scannable barcodes in Code 128, EAN-13, UPC-A, Code 39, ITF-14 and more, with check digits added for you. Download SVG or PNG, or copy the image.

Authentication

All API requests require a valid API key passed in the Authorization header as a Bearer token.

Rate Limit

20 requests per minute

Endpoints

1 endpoint available

Overview

Draw a barcode in one of 12 symbologies. The value is checked for the symbology you pick, and check digits are added where the symbology has one (EAN-13 from 12 digits, for example).

Symbologies

  • Retail: EAN13, UPC (UPC-A), EAN8, UPCE
  • General purpose: CODE128 (default), CODE39, CODE93
  • Shipping: ITF14, ITF
  • Specialist: codabar, MSI, pharmacode

Output formats

  • png (default): the response body is the PNG file (Content-Type: image/png).
  • svg: the response body is the SVG file (Content-Type: image/svg+xml).
  • base64: JSON with the PNG as a data URL in image, and text, the full value that was encoded including any check digit.

Notes

  • width is the bar width in pixels, height the bar height, and margin the blank border. scale (1 to 4) multiplies all sizes. An image can be at most 8000 pixels on a side.
  • The human-readable text under the bars is set in a monospace font. In SVG output the viewer picks the font; in PNG output the server's font is used. Set displayValue to false for bars only.
  • Colours are hex only. Set transparent to true for no background. Scanners read dark bars on a light background best.
  • If the value is not valid for the symbology the API returns 400 and says what the symbology accepts.

Endpoints

POST
https://opentools.ca/api/v1/tools/barcode-generator
Generate a barcode image

Request Body

Content-Type: application/json

ParameterTypeRequiredDescription
value
string
Required
The value to encode, 1 to 200 characters. What is valid depends on the symbology.
symbology
string
Enum: EAN13, UPC, EAN8, UPCE, CODE128, CODE39, CODE93, ITF14, ITF, codabar, MSI, pharmacode
OptionalBarcode type.Default: CODE128
format
string
Enum: png, svg, base64
Optionalpng and svg return the image file; base64 returns JSON with a PNG data URL.Default: png
width
number
OptionalWidth of the thinnest bar in pixels, 1 to 10.Default: 2
height
number
OptionalBar height in pixels, 20 to 500.Default: 100
displayValue
boolean
OptionalShow the value as text under the bars.Default: true
fontSize
number
OptionalText size in pixels, 8 to 60.Default: 20
margin
number
OptionalBlank border (quiet zone) in pixels, 0 to 100.Default: 10
lineColor
string
OptionalBar and text colour, as hex.Default: #000000
background
string
OptionalBackground colour, as hex.Default: #ffffff
transparent
boolean
OptionalNo background. Overrides background.Default: false
scale
number
OptionalMultiplies width, height, font size and margin, 1 to 4.Default: 1

Response Example

With format "png" or "svg" the body is the image file itself. With format "base64":
{
  "success": true,
  "symbology": "EAN13",
  "text": "5901234123457",
  "width": 234,
  "height": 142,
  "format": "base64",
  "mimeType": "image/png",
  "image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}

Error Codes

400
Bad Request - Value not valid for the symbology, invalid option, or an image over 8000 pixels on a side
401
Unauthorized - Invalid or missing API key
403
Forbidden - API key inactive, expired, or request from a disallowed IP
429
Too Many Requests - Rate limit exceeded
500
Internal Server Error

Code Examples

# Save a PNG
curl -X POST https://opentools.ca/api/v1/tools/barcode-generator \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"symbology": "EAN13", "value": "590123412345", "scale": 2}' \
  -o barcode.png

# SVG
curl -X POST https://opentools.ca/api/v1/tools/barcode-generator \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"value": "OpenTools-2026", "format": "svg"}' \
  -o barcode.svg

Ready to get started?

Create an API key to start using the Barcode Generator API.

Rather use it in your browser? Open the Barcode Generator