The Barcode API generates custom barcodes for any text. It supports multiple barcode types, custom dimensions, and several image formats.
https://api.api-ninjas.com/v1/barcodegenerate
Returns a barcode image binary specified by input parameters.
text
requiredText to encode in the barcode.
type
optionalType of barcode to generate. Must be one of: code39
, code128
, ean
, ean13
, ean8
, gs1
, gtin
, isbn
, isbn10
, isbn13
, issn
, jan
, pzn
, upc
, upca
. Default is upc
.
format
optionalImage format to return. Must be one of: png
, svg
. Default is png
.
include_text
optionalWhether to include the text below the barcode. Must be true
or false
. Default is true
.
X-Api-Key
requiredAPI Key associated with your account.
Accept
may be requiredDepending on the programming language and HTTP request library (e.g. Python's requests
), you may need to add a header indicating the content type(s) to accept in the result. Set the value according to your format
parameter:
png
: image/png
svg
: image/svg+xml
https://api.api-ninjas.com/v1/barcodegenerate?format=png&type=upc&text=123456789012
Headers
X-Api-Key
Log in or sign up to get your API Key
1
2
3
4
5
6
7
8
9
10
11
12
import requests
import shutil
text = '123456789012'
barcode_type = 'upc'
api_url = 'https://api.api-ninjas.com/v1/barcodegenerate?text={}&type={}'.format(text, barcode_type)
response = requests.get(api_url, headers={'X-Api-Key': 'YOUR_API_KEY', 'Accept': 'image/png'}, stream=True)
if response.status_code == requests.codes.ok:
with open('barcode.png', 'wb') as out_file:
shutil.copyfileobj(response.raw, out_file)
else:
print("Error:", response.status_code, response.text)
If your programming language is not listed in the Code Example above, you can still make API calls by using a HTTP request library written in your programming language and following the above documentation.