Barcode API

Put a URL in an image tag and get a scannable PNG back. Need vector output? POST JSON for SVG. Same encoder as the generator, free, no API key.

  • Free · no API key
  • CORS enabled
  • Edge-cached PNG

1 · Type

11 digits, or 12 to verify the check digit

3 · Size
3
30
5
4 · Style
text
fg
bg
rotate

Response

200 OKimage/png
Size
369 × 159 px
DPI
300
Module
3 px
Cache
1 year

Request

GET
https://barcodefox.com/api/v1/barcode?type=upca&data=03600029145
Open PNG

URL calls always return PNG. For SVG, POST the same parameters as JSON.

Quickstart

Two ways to call it

GET/api/v1/barcode

URL → PNG

Every parameter fits in the query string, so the URL is the barcode. Put it in an <img> tag, a spreadsheet IMAGE() formula, an email template or a Markdown file. A GET request always returns PNG.

<img src="https://barcodefox.com/api/v1/barcode?type=ean13&amp;data=400638133393&amp;scale=4"
     alt="EAN-13 barcode 4006381333931">
  • image/png
  • Cached for a year
  • No JavaScript needed
POST/api/v1/barcode

JSON → SVG or PNG

Send the same parameters as a JSON body. Use "format": "svg" (the default) for vector output sized in millimetres, or "png" for a raster image.

curl -X POST https://barcodefox.com/api/v1/barcode \
  -H "content-type: application/json" \
  -d '{"type":"code128","data":"BFX-0042","format":"svg"}' \
  -o barcode.svg
  • image/svg+xml
  • image/png
  • Body ≤ 8 KB

Reference

Endpoints

Base URL https://barcodefox.com/api/v1

MethodPathReturns
GET/barcodePNG image from query parameters
POST/barcodeSVG (default) or PNG from a JSON body
POST/validateJSON: whether the data is valid, its normalized form and check digit
GET/formatsJSON list of supported types and their rules

Parameters

Query string for GET, JSON keys for POST. Only type and data are required.

NameValuesDefaultDescription
typerequiredstring—Barcode type. One of the 8 values listed below.
datarequiredstring—Content to encode, up to 128 characters. Check digits are added when missing and verified when present.
formatsvg | pngsvgPOST only. GET always returns PNG and rejects any other value.
scale1–103Pixels per module (narrowest bar) in PNG output.
height5–20030Bar height in modules. Decimals are allowed.
margin0–405 / 10Quiet zone on each side, in modules: 5 for UPC, EAN and ITF-14, 10 for the others.
textbooleantruePrint the human-readable text under the bars.
fghex141413Bar color, with or without the #.
bghex | transparentFFFFFFBackground color, or transparent.
rotate0 | 90 | 180 | 2700Clockwise rotation in degrees.
dpi72–1200300Resolution stored in the PNG, so print apps place it at the right size.

Errors

Errors are JSON, even on the PNG endpoint, so an image tag shows nothing instead of a wrong barcode.

  • 400invalid_paramA parameter is missing or out of range.
  • 400invalid_dataThe data cannot be encoded as that type.
  • 400unsupported_formatUnknown type, or a GET request asked for something other than PNG.
  • 400too_largeThe PNG would be larger than 4000 × 4000 px.
  • 413payload_too_largeThe POST body is over 8 KB.
  • 429rate_limitedToo many requests. Wait for the Retry-After seconds.
HTTP/1.1 400 Bad Request
content-type: application/json

{
  "error": {
    "code": "invalid_data",
    "message": "Check digit should be 1, not 7",
    "param": "data"
  }
}

Limits & caching

  • 120
    Requests per minute

    Per IP address, counted at each edge location, so treat it as approximate.

  • 4000
    Max PNG size in px

    Width and height, after scale and rotation.

  • 1 yr
    GET cache

    The same URL always returns the same image, so it is safe to hotlink.

  • $0
    Price

    No key and no sign-up. Commercial use is allowed.

8 types

Supported type values

  • upcaUPC-A

    11 digits, or 12 to verify the check digit

    ?type=upca&data=03600029145
  • ean13EAN-13

    12 digits, or 13 to verify the check digit

    ?type=ean13&data=400638133393
  • ean8EAN-8

    7 digits, or 8 to verify the check digit

    ?type=ean8&data=9638507
  • code128Code 128

    Any printable ASCII, up to 48 characters

    ?type=code128&data=BFX-2026-0042
  • gs1-128GS1-128

    Application Identifiers in brackets, e.g. (01)…(17)…

    ?type=gs1-128&data=(01)09506000134352(17)261231
  • itf14ITF-14

    13 digits, or 14 to verify the check digit

    ?type=itf14&data=1540014128876
  • code39Code 39

    A–Z, 0–9 and space - . $ / + %

    ?type=code39&data=FOX-42
  • codabarCodabar

    Digits and - $ : / . +, wrapped in A–D start/stop

    ?type=codabar&data=A40156B

FAQ

API questions

Rather not call a server? The online generator makes the same barcodes in your browser.

Why does the URL version only return PNG?

A URL usually goes where an image goes: an <img> tag, an email, a spreadsheet or a Markdown file, and PNG works in all of them. For vector output, POST the same parameters as JSON with "format": "svg".

Do I need an API key?

No. The API is free, needs no sign-up and allows commercial use. Each IP address can make about 120 requests per minute; past that you get a 429 response with a Retry-After header.

Can I hotlink the image on my site?

Yes. The same URL always returns the same image, and the response may be cached for a year, so browsers and CDNs only fetch it once.

How do I print the barcode at the right size?

PNG files carry a resolution (300 DPI unless you set dpi), so print apps place them at a matching physical size. For exact dimensions, POST for SVG: it is sized in millimetres at 0.33 mm per module.

Is the data I encode stored?

The API has no database and does not save what you encode. GET responses are kept in the edge cache so repeat requests are fast; POST responses are never cached.