Barcode Generation
The /barcode endpoint generates barcode images from a data string. It supports several standard barcode formats and renders the result as SVG or PNG.
Format details
- Code 128: Encodes any printable ASCII character (codes 32–126).
- EAN-13 / EAN-8 / UPC-A: Numeric only. The check digit is computed automatically if omitted, or validated if provided.
- Code 39: Alphanumeric (
A-Z,0-9, space,- . $ / + %). Input is auto-uppercased; start/stop characters are added automatically.
curl -X GET \ "https://api.moxon.dev/v5/barcode"Send the request to see the response here.
datastringrequiredData string to encode in the barcode
typestringoptionalDefault:
code128.Barcode format:
code128,ean13,ean8,upca,code39- code128
- ean13
- ean8
- upca
- code39
format"svg" | "png"optionalDefault:
svg.Output format:
svgorpngwidthnumberoptionalDefault:
2.Bar unit width in pixels (1–5)
heightnumberoptionalDefault:
100.Bar height in pixels (50–300)
colorstringoptionalDefault:
#000000.Bar color in hexadecimal (e.g.
000000)bgstringoptionalDefault:
#ffffff.Background color in hexadecimal (e.g.
ffffff)
By default (format=svg), the endpoint returns an inline SVG image (Content-Type: image/svg+xml), usable in an <img> tag:
<img src="https://api.moxon.dev/v5/barcode?data=Hello123" alt="Barcode" />With format=png, the response is a raw PNG buffer (Content-Type: image/png):
<img src="https://api.moxon.dev/v5/barcode?data=Hello123&format=png" alt="Barcode" />- 400
Please provide data to encode (?data={string})Thedataparameter is missing - 400
Type must be one of: code128, ean13, ean8, upca, code39Thetypevalue is not valid - 400
Format must be one of: svg, pngTheformatvalue is not valid - 400
Width must be between 1 and 5Thewidthparameter is out of the allowed range - 400
Height must be between 50 and 300Theheightparameter is out of the allowed range - 400
Please provide valid dimensions (&width={px}&height={px})Thewidthorheightparameter is not a valid number - 400
Code 128 only supports ASCII 32-126 (invalid char: "{ch}")A character indatais outside the Code 128 supported range - 400
EAN-13 requires 12 or 13 digitsThedatastring does not have the correct number of digits - 400
Invalid EAN-13 check digit (expected {expected}, got {actual})The provided EAN-13 check digit does not match the computed value - 400
EAN-8 requires 7 or 8 digitsThedatastring does not have the correct number of digits - 400
Invalid EAN-8 check digit (expected {expected}, got {actual})The provided EAN-8 check digit does not match the computed value - 400
UPC-A requires 11 or 12 digitsThedatastring does not have the correct number of digits - 400
Code 39 invalid character: "{ch}". Allowed: A-Z, 0-9, space, - . $ / + %A character indatais not allowed in Code 39 - 400
Invalid color (use hex like ff6600)Acolororbgvalue is not a valid hexadecimal color
Last updated on July 26, 2026