McAPI - QR API JavaScript / Node

JavaScript / Node sample code to create QR barcodes with the McAPI QR REST API service.

Requirements: A free RapidAPI account. All samples below can be tried with the free plan of the McAPI Barcode API. Replace YOUR_API_KEY with your own api key.

The sample can be used with the free tier of the API, see RapidAPI McAPI QR Listing for available plans.

See the overview page for available parameters and error codes.

Create QR code using Node with request module

Although deprecated, the request module is still in wide use. Shown is the creation of a QR code with JavaScript encoding the URL https://mcapi.io. The code is created in red (dot color) and blue (finder color) with a dot size of 10 pixels. The dot style is set to "1" (for separated dots), the shape is set to "1" (for dots in disc or circle shape). The output format is "png". As the QR error correction is not specified, the API will use ECC level "M", sufficient for most purposes. Use "Q" (numeric value "3") for highest ECC.

The source code:

const request = require('request');
const options = {
  method: 'POST',
  url: 'https://mcapi-qr.p.rapidapi.com/',
  headers: {
    'content-type': 'application/json',
    'x-rapidapi-key': 'YOUR_API_KEY',
    'x-rapidapi-host': 'mcapi-qr.p.rapidapi.com',
  },
  body: {
    data: 'https://mcapi.io',
    dotSize: 10,
    finderColor: '#0000FF',
    dotColor: '#FF0000',
    dotStyle: 1,
    dotShape: 1,
    format: 'png'
  },
  json: true
};

request(options, function (error, response, body) {
	if (error) throw new Error(error);

	console.log(body);
});

The data will be delivered as a JSON object in body, e.g.:

{
  "service":"McAPI QR Code Generator, https://mcapi.io",
  "version":"V1",
  "format":"png",
  "code":"data:image/png;base64,iVBORw ... K5CYII="
}

McAPI QR API - Sample QR barcode with JavaScript

The returned code from the Node request:

Image of McAPI QR API Sample Barcode Node JS

Create QR code using Node with axios module

A modern, promise based replacement for request is the axios module which is almost 100% source code compatible.

Here's the same API call as above with axios:

var axios = require("axios").default;

var options = {
  method: 'POST',
  url: 'https://mcapi-qr.p.rapidapi.com/',
  headers: {
    'content-type': 'application/json',
    'x-rapidapi-key': 'YOUR_API_KEY',
    'x-rapidapi-host': 'mcapi-qr.p.rapidapi.com'
  },
  data: {
    data: 'https://mcapi.io',
    dotSize: 10,
    finderColor: '#0000FF',
    dotColor: '#FF0000',
    dotStyle: 1,
    dotShape: 1,
    format: 'png'
  }
};

axios.request(options).then(function (response) {
	console.log(response.data);
}).catch(function (error) {
	console.error(error);
});

Scanning QR codes

It's recommended to test scan the created QR codes. On iOS, the built-in camera app will natively detect and scan QR codes in the camera's view. For Android, use Google's Zxing Barcode Scanner app (free). Both apps will scan from the computer display, no need to print the codes.

Back to McAPI QR API main page.