Skip to main content

Node.js Example

First, sign up for the basic plan for a free development API key. Please replace API_KEY in the code example below with your own API key.

Follow these steps to create a sample NodeJS project:

mkdir ZplTest
cd ZplTest
npm init --yes
npm install request fs

Create a new file zpl.js with the following content:

var request = require("request");
var fs = require('fs');

var API_KEY = 'API_KEY';

var options = {
method: 'POST',
url: 'https://html-to-zpl.p.rapidapi.com/html2zpl',
headers: {
'x-rapidapi-host': 'html-to-zpl.p.rapidapi.com',
'x-rapidapi-key': API_KEY,
'content-type': 'application/x-www-form-urlencoded',
useQueryString: true
},
form: {
width: '4',
height: '2',
html: '<h1 style="font-size:40pt;margin:0.5in">Hello World!<h1> <p style="font-size:25pt;margin:0.8in">ZPL label generated by <u>htmltozpl.com</u></p>'
}
};

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

fs.writeFile("node-html-to-zpl-example.zpl", body, function(err) {
if (err) return console.log(err);
console.log("Saving the resulting ZPL.")
});
});

Run it by typing:

node zpl.js

You should see the resulting ZPL written on the console, and also saved to the file node-html-to-zpl-example.zpl.