McAPI - Barcode API Overview

This very comprehensive Barcode REST API creates all common linear and 2D barcode symbologies. In total, more than twenty symbologies are supported for use in retail, logistics, transportation, social media / marketing, pharma. The barcodes can be widely customized with options for size, human readable text, check digit generation and bar width reduction. Codes are returned from the API as PDF, SVG, PNG or TIFF. Extensive sample code illustrates barcode creation in Node / JS, Python, Ruby, Swift, PHP, C# and other languages and environments.

All barcodes are guaranteed to conform to the GS1 specifications and the respective ISO standards.

Supported barcode symbologies:

  • EAN 8
  • EAN 13 (with optional add-on)
  • ISBN 10 (with optional add-on)
  • ISBN 13 (with optional add-on)
  • ISSN (with optional add-on)
  • UPC-A (with optional add-on)
  • UPC-E
  • Code 128 A, B, C
  • Code 128 GS1
  • Code 2/5 Interleaved
  • Code 2/5 Industrial
  • Code ITF-14
  • Code 39 / 39 Extended
  • PZN 7 / PZN 8
  • Laetus
  • Codabar
  • Datamatrix (2D)
  • Datamatrix GS1 (2D)
  • PDF 417 (2D)
  • QR (2D)
  • Aztec (2D)

Supported barcodes types at a glance (click for full size, download as PDF):

McAPI Barcode API Sample Barcodes

McAPI Barcode API - Plans and pricing

We provide a generous free plan with this API. See the RapidAPI listing for all plans and pricing.

McAPI Barcode API - Specifications

Version:

V1.0

Protocol:

https

URL:

https://mcapi-barcode.p.rapidapi.com

Endpoint:

/

Method:

POST

McAPI Barcode API - Sample cURL call

Shown is a cURL request to create and return a Code 128 barcode with the text 123456. The module width is set to 0.5mm, the height is set to 20mm, the size of the human readable text under the barcode is set to 10 points. The code is returned as a base64 encoded PDF (replace YOUR_API_KEY with your RapidAPI key):
curl --request POST \
--url https://mcapi-barcode.p.rapidapi.com/ \
--header 'content-type: application/json' \
--header 'x-rapidapi-host: mcapi-barcode.p.rapidapi.com' \
--header 'x-rapidapi-key: YOUR_API_KEY' \
--data '{
  "data": "123456",
  "type": 7,
  "moduleWidth": 0.5,
  "moduleHeight": 20,
  "hrSize": 10,
  "format": "pdf"
}'

McAPI Barcode API - Sample response

Shown is the response from the cURL request above (the returned PDF is shortened):
{
  "service": "McAPI Barcode Generator, https://mcapi.io"
  "version": "V1"
  "format": "pdf"
  "code": "data:application/pdf;base64,JVBE ... Cg=="
}

McAPI Barcode API - Sample barcodes

Shown is the returned Code 128 from the cURL call above (screenshot from the rendered PDF, original PDF):

McAPI Barcode API Sample Barcode Code 128

The barcode attributes can be widely configured. GS1 compliant EAN 13 barcode in SC 2 size:

Image of McAPI Barcode API EAN 13 Barcode

Same EAN 13 with reduced height (50%):

Image of McAPI Barcode API EAN 13 Truncated Barcode

Barcode with supplemental text:

Image of McAPI Barcode API EAN 13 Price Best before Barcode

Barcode without text line:

Image of McAPI Barcode API EAN 13 No text Barcode

Sample Datamatrix code:

Image of McAPI Barcode API Datamatrix 2D Barcode

Sample QR code:

Image of McAPI Barcode API QR URL Barcode

McAPI Barcode API - Reference

Describes parameters for barcode creation and return format. All parameters are case-sensitive.

Parameters to control the barcode creation

  • Name: data

    Description: Data to encode in the barcode.

    Type: String

    Required: Yes

    Values: max. 2,000 characters

    Default: n/a

    Sample JSON:

    "data" : "123456"

    Applies to all symbologies. See table for type-parameter for expected data.

  • Name: type

    Description: The barcode type to be created.

    Type: Numeric

    Required: No

    Values:

    • 0: EAN 8
    • 1: EAN 13
    • 2: ISBN 10
    • 3: ISBN 13
    • 4: ISSN
    • 5: UPC-A
    • 6: UPC-E
    • 7: Code 128
    • 8: Code 128 GS1
    • 9: Code 2/5 Interleaved
    • 10: Code 2/5 Industrial
    • 11: Code ITF-14
    • 12: Code 39 / 39 Extended
    • 13: PZN 7 / PZN 8
    • 14: Laetus
    • 15: Codabar
    • 16: Datamatrix
    • 17: Datamatrix GS1
    • 18: PDF 417
    • 19: QR
    • 20: Aztec

    Default: 7 (Code 128)

    Sample JSON:

    "type" : 7

    Depending on the code type, further parameters may be set. Code type selection also determines the data that has to be supplied, e.g. for EAN 13 the API will expect 12 or 13 digits.

    SymbologyDataParametersRemarks
    EAN 87 or 8 digitssize, truncate
    EAN 1312 or 13 digitssize, truncate, addon, lmi1
    ISBN 10ISBN 10 Nr., e.g. 1-123-12345-Xsize, truncate, addon, lmi1
    ISBN 13ISBN 13 Nr., e.g. 978-1-123-12345-6size, truncate, addon, lmi1
    ISSNEight digit ISSN Nr., e.g. 1234-5678size, truncate, addon, lmi1, 2
    UPC-A11 or 12 digitssize, truncate1
    UPC-E7 or 8 digitssize, truncateData must begin with "1" or "0"
    Code 128Digits, letters, ASCII character set (max. 64 chars)moduleWidth, -HeightAutomatic selection of Code 128 sub types A, B, C. Code 128 is always created with a check digit.
    Code 128 GS1Digits, letters, parenthesized application identifier (max. 64 chars)moduleWidth, -HeightAutomatic selection of Code 128 sub types A, B, C. Code 128 GS1 is always created with a check digit.

    Enter your data including application identifiers, e.g. (01)1234567890. The software will automatically insert all required FNC1 symbols.
    Code 2/5 InterleavedDigits 0-9 (max. 64 digits) moduleWidth, -Height, ratioCode will be created with check digit, the check digit will not be displayed under the barcode
    Code 2/5 IndustrialDigits 0-9 (max. 64 digits)moduleWidth, -Height, ratio, calculateCheckDigit, displayCheckDigit
    Code ITF-14Digits 0-9 (13 or 14 digits), with spacesmoduleWidth, -Height, ratioProvide a complete 14-digit GTIN including the GTIN check digit. If 13 digits are given the app will calculate and append the GTIN check digit. Software will add "bearer frame". Recommended settings: moduleWidth: 0.5mm minimum, -Height: 32mm minimum
    Code 39 / 39 ExtendedDigits, letters (max. 64 chars)moduleWidth, -Height, ratio, calculateCheckDigit, displayCheckDigitAutomatic selection of Code 39 / Code 39 Extended.
    PZN 7/87 or 8 digitsmoduleWidth, -HeightData must be a complete PZN, i.e. including modulo-11 check digit. Software will add PZN text. Recommended settings: moduleWidth: min. 0.25mm, -Height: 8-20mm
    LaetusDigits 0-9, max. value 131070moduleWidth, -Height
    CodabarDigits 0-9 (max. 64 digits)moduleWidth, -HeightSpecify start / stop symbols with your data, e.g. A123456A. Available start / stop symbols are "A", "B", "C", "D". Codabar is always created without a check digit.
    DatamatrixUp to 2000 chars, extended ASCII setmoduleWidthSquare modules, width = height. Datamatrix codes are created as ECC200 variant.
    Datamatrix GS1Up to 2000 chars, extended ASCII setmoduleWidthSquare modules, width = height.

    Enter your data including application identifiers, e.g. (01)1234567890. The software will automatically insert all required FNC1 symbols.

    Datamatrix codes are created as ECC200 variant.
    PDF 417Up to 2000 chars, extended ASCII setmoduleWidthModule ratio height : width = 3 : 1
    QRUp to 2000 chars, Unicode compatiblemoduleWidthSquare modules, width = height. QR codes are created with Medium ECC level.
    AztecUp to 2000 chars, extended ASCII setmoduleWidthSquare modules, width = height

    1) EAN 13, ISSN, ISBN 10, ISBN 13 and UPC-A can carry a satellite, or "add on", barcode. This add on can encode two or five digits.

    2) To provide a variant no. for ISSN, append the two digit number to your ISSN, separated by semicolon, e.g. 1234-5678;05. If no variant is specified, "00" will be used.

    Note: With all retail barcodes (EAN / UPC / ISBN), the software will always recalculate the respective check digit for the selected code to assure a valid symbol.

  • Name: moduleWidth

    Description: Width of the narrowest bar in mm.

    Type: Number

    Required: No

    Values: 0.2 to 10mm

    Default: 0.5mm

    Sample JSON:

    "moduleWidth" : 0.5

    Applies to the following symbologies:

    • Code 128
    • Code 128 GS1
    • Code 2/5 Interleaved
    • Code 2/5 Industrial
    • Code ITF-14
    • Code 39 / 39 Extended
    • PZN 7 / PZN 8
    • Laetus
    • Codabar
    • Datamatrix
    • Datamatrix GS1
    • PDF 417
    • QR
    • Aztec

  • Name: moduleHeight

    Description: Height of the barcode excluding the text line in mm.

    Type: Number

    Required: No

    Values: 2 to 100mm

    Default: 15mm

    Sample JSON:

    "moduleHeight" : 15

    Applies to the following symbologies:

    • Code 128
    • Code 128 GS1
    • Code 2/5 Interleaved
    • Code 2/5 Industrial
    • Code ITF-14
    • Code 39 / 39 Extended
    • PZN 7 / PZN 8
    • Laetus
    • Codabar

  • Name: ratio

    Description: Ratio of the width of the widest bar to width of the narrowest bar.

    Type: Number

    Required: No

    Values: 2.0 to 3.0

    Default: 2.5

    Sample JSON:

    "ratio" : 2.5

    Applies to the following symbologies:

    • Code 2/5 Interleaved
    • Code 2/5 Industrial
    • Code ITF-14
    • Code 39 / 39 Extended
    • PZN 7 / PZN 8

  • Name: calculateChecksum

    Description: Create barcode with checksum.

    Type: String

    Required: No

    Values: "true" or "false"

    Default: "true"

    Sample JSON:

    "calculateChecksum" : "true"

    Applies to the following symbologies:

    • Code 2/5 Interleaved
    • Code 2/5 Industrial
    • Code 39 / 39 Extended
    • PZN 7 / PZN 8

  • Name: displayChecksum

    Description: Display checksum with text line. Ignored, if the code is created without checksum.

    Type: String

    Required: No

    Values: "true" or "false"

    Default: "true"

    Sample JSON:

    "displayChecksum" : "true"

    Applies to the following symbologies:

    • Code 2/5 Interleaved
    • Code 2/5 Industrial
    • Code 39 / 39 Extended
    • PZN 7 / PZN 8

  • Name: hrText

    Description: Display text line under the barcode.

    Type: String

    Required: No

    Values: "true" or "false"

    Default: "true"

    Sample JSON:

    "hrText" : "true"

    Applies to the following symbologies:

    • EAN 8
    • EAN 13
    • ISBN 10 *
    • ISBN 13 *
    • ISSN *
    • UPC-A
    • UPC-E
    • Code 128
    • Code 128 GS1
    • Code 2/5 Interleaved
    • Code 2/5 Industrial
    • Code ITF-14
    • Code 39 / 39 Extended
    • PZN 7 / PZN 8
    • Codabar

    Note: 2D barcodes are always created without text as the encoded data is usually too much to be displayed. For small amounts of text, use the over and under parameters. All text is created using an OCR-B alike font.

    * When set to "false", the ISBN / ISSN text lines will not be displayed above the code.

  • Name: hrSize

    Description: Font size of the text line under the barcode in points.

    Type: Number

    Required: No

    Values: 4 to 40pt.

    Default: 10pt.

    Sample JSON:

    "hrSize" : 10

    Applies to the following symbologies:

    • Code 128
    • Code 128 GS1
    • Code 2/5 Interleaved
    • Code 2/5 Industrial
    • Code ITF-14
    • Code 39 / 39 Extended
    • PZN 7 / PZN 8
    • Codabar

    Note: With retail codes (EAN / UPC / ISBN) the font size is determined automatically to fit the text under the barcode.

  • Name: over

    Description: Additional text to put above the barcode.

    Type: String

    Required: No

    Values: max. 30 characters

    Default: ""

    Sample JSON:

    "over" : "Paperclips"

    Applies to all symbologies except Laetus. The text may only contain ASCII characters. All text is created using an OCR-B alike font.

  • Name: under

    Description: Additional text to put beneath the barcode.

    Type: String

    Required: No

    Values: max. 30 characters

    Default: ""

    Sample JSON:

    "under" : "$2.99"

    Applies to all symbologies except Laetus. The text may only contain ASCII characters. All text is created using an OCR-B alike font.

  • Name: suppSize

    Description: Font size of the supplemental text above and below the barcode in points.

    Type: Number

    Required: No

    Values: 4 to 36pt.

    Default: 8pt.

    Sample JSON:

    "suppSize" : 8

    Applies to all symbologies except Laetus.

  • Name: size

    Description: SC size of barcode. The default is SC 2 (= 100% standard size).

    Type: Number

    Required: No

    Values: 0-9

    Default: 2

    Sample JSON:

    "size" : 9

    Retail codes (EAN / UPC / ISBN) only. See truncate parameter to reduce the height of the code. For an introduction to SC sizes see here.

  • Name: truncate

    Description: Truncate height of barcode. Given in percent, e.g. "80" results in a code that has 20% of the standard height.

    Type: Number

    Required: No

    Values: 0-80

    Default: 0

    Sample JSON:

    "truncate" : 50

    Retail codes (EAN / UPC / ISBN) only.

  • Name: addon

    Description: Display a two or five digit add on.

    Type: String

    Required: No

    Values: String of two or five numbers, e.g. "12" or "12345"

    Default: ""

    Sample JSON:

    "addon" : "90000"

    Applies to the following symbologies:

    • Code EAN 13
    • Code ISBN 10
    • Code ISBN 13
    • Code ISSN
    • Code UPC-A

  • Name: lmi

    Description: Display light margin indicator (">", aka. "chevron") to the right of the barcode.

    Type: String

    Required: No

    Values: "true" or "false"

    Default: "true"

    Sample JSON:

    "lmi" : "true"

    Applies to the following symbologies:

    • EAN 13
    • ISBN 10
    • ISBN 13
    • ISSN

  • Name: reduction

    Description: Reduce bar width to compensate for dot gain during printing. Ask your printer for recommendations.

    Type: Number

    Required: No

    Values: 0 to 50%

    Default: 0

    Sample JSON:

    "reduction" : 5

    Applies to all linear symbologies. Ignored for 2D symbologies.

  • Name: margin

    Description: Margin around the barcode in mm.

    Type: Number

    Required: No

    Values: 0 to 20mm

    Default: 8mm

    Sample JSON:

    "margin" : 4

    Applies to all symbologies. This parameter can also be used to control the placement of additional text: The larger the margin, the farther away from the code the text is placed.

Parameters to control the return format

  • Name: format

    Description: Output data format.

    Type: String

    Required: No

    Values: "pdf", "svg", "png", "tiff"

    Default: "pdf"

    Sample JSON:

    "format" : "svg"

    Data is always returned as base64 encoded string. Raster formats PNG and TIFF are created with 72dpi resolution. SVGs are created with 96dpi base resolution as is assumed by CSS and all major browsers.

  • Name: header

    Description: Prepend header to base64 string.

    Type: String

    Required: No

    Values: "true" or "false"

    Default: "true"

    Sample JSON:

    "header" : "false"

    Depending on the data format, the following headers will be used:

    • PDF: data:application/pdf;base64,
    • SVG: data:image/svg+xml;base64,
    • PNG: data:image/png;base64,
    • TIFF: data:image/tiff;base64,

    As a rule, leave the header in if you plan to inject the returned code in an HTML DOM or write out img-tags. If you plan to write the code to a file, set the parameter to false. See the sample code for more.

McAPI Barcode API - Error codes and messages

Upon success, the API returns a status code of 200. With any error, the API will instead return a status code of 400. Also provided is a status text with more information. The following example shows the response for a messed up data package (with the cURL from the introduction we changed the JSON block from "format": "pdf" to "format: "pdf"). This will cause the JSON parser in the API's event handler to raise an exception; the handler will then return:

Malformed event parameter

Other error messages:

  • No data specified - data property absent or empty string
  • Data length > 2.000 chars. - data string too long
  • Invalid format specification - format not one of the supported formats
  • Invalid header argument - header not "true" or "false"
  • Code parameters invalid

    Catch all error for invalid arguments for the barcode:

    • type not between 0 and 20 or not numeric
    • moduleWidth not between 0.1 and 10 or not numeric
    • moduleHeight not between 2 and 100 or not numeric
    • ratio not between 2.0 and 3.0 or not numeric
    • calculateChecksum not "true" or "false" or not string
    • displayChecksum not "true" or "false" or not string
    • hrText not "true" or "false" or not string
    • hrSize not between 4 and 40 or not numeric
    • over longer than 30 chars or not string
    • under longer than 30 chars or not string
    • suppSize not between 4 and 36 or not numeric
    • size not between 0 and 9 or not numeric
    • truncate not between 0 and 80 or not numeric
    • addon not 2 or 5 chars or not string
    • lmi not "true" or "false" or not string
    • reduction not between 0 and 50 or not numeric
    • margin not between 0 and 20 or not numeric

    In addition, this error will be returned if invalid data was specified for the requested barcode type, e.g. letters for Code EAN 13.

McAPI Barcode API - Sample code and snippets