barcode reader API in JavaScript and Web API

Write code in JavaScript to make barcode reader API with this How-To tutorial

On this page you will learn from code samples for programming in JavaScript. Barcode reader API in JavaScript can be implemented with Web API. Web API is the Web API with a set of tools for documents manipulation, data conversion, data extraction, splitting and merging of documents. Includes image recognition, built-in OCR, barcode generation and barcode decoders to decode bar codes from scans, pictures and pdf.

You will save a lot of time on writing and testing code as you may just take the code below and use it in your application. In order to implement this functionality, you should copy and paste code below into your app using code editor. Then compile and run your application. Enjoy writing a code with ready-to-use sample JavaScript codes to implement barcode reader API using Web API.

Visit our website provides for free trial version of Web API. Free trial includes lots of source code samples to help you with your JavaScript project.

Try Web API today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)

var https = require("https"); // Use "npm install request" command to install. var request = require("request"); // The authentication key (API Key). // Get your own by registering at const API_KEY = "***********************************"; // Direct URL of source file to search barcodes in. const SourceFileUrl = ""; // Comma-separated list of barcode types to search. // See valid barcode types in the documentation const BarcodeTypes = "Code128,Code39,Interleaved2of5,EAN13"; // Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'. const Pages = ""; // Sample profile that sets advanced conversion options // Advanced options are properties of Reader class from Bytescout BarCodeReader used in the back-end: // const Profiles = '{ "profiles": [ { "profile1": { "FastMode": true } } ] }'; // Prepare request to `Barcode Reader` API endpoint var queryPath = `/v1/barcode/read/from/url?types=${BarcodeTypes}&pages=${Pages}&url=${SourceFileUrl}&profiles=${Profiles}&async=True`; var reqOptions = { host: "", path: encodeURI(queryPath), headers: { "x-api-key": API_KEY } }; // Send request https.get(reqOptions, (response) => { response.on("data", (d) => { // Parse JSON response var data = JSON.parse(d); if (data.error == false) { console.log(`Job #${data.jobId} has been created!`); checkIfJobIsCompleted(data.jobId, data.url); } else { // Service reported error console.log(data.message); } }); }).on("error", (e) => { // Request error console.error(e); }); function checkIfJobIsCompleted(jobId, resultFileUrlJson) { let queryPath = `/v1/job/check?jobid=${jobId}`; let reqOptions = { host: "", path: encodeURI(queryPath), method: "GET", headers: { "x-api-key": API_KEY } }; https.get(reqOptions, (response) => { response.on("data", (d) => { response.setEncoding("utf8"); // Parse JSON response let data = JSON.parse(d); console.log(`Checking Job #${jobId}, Status: ${data.status}, Time: ${new Date().toLocaleString()}`); if (data.status == "working") { // Check again after 3 seconds setTimeout(function () { checkIfJobIsCompleted(jobId, resultFileUrlJson); }, 3000); } else if (data.status == "success") { request({ method: 'GET', uri: resultFileUrlJson, gzip: true }, function (error, response, body) { // Parse JSON response let respJsonFileArray = JSON.parse(body); respJsonFileArray.forEach((element) => { console.log("Found barcode:"); console.log(" Type: " + element["TypeName"]); console.log(" Value: " + element["Value"]); console.log(" Document Page Index: " + element["Page"]); console.log(" Rectangle: " + element["Rect"]); console.log(" Confidence: " + element["Confidence"]); console.log(); }, this); }); } else { console.log(`Operation ended with status: "${data.status}".`); } }) }); }

Try Web API today:  60 Day Free Trial (on-premise) or  Web API (on-demand version)



Get 60 Day Free Trial or Visit Web API Home Page

Explore Web API Documentation

Get Web API Free Training


Get Your Free API Key

Explore Web API Documentation

Related Samples: