Skip to content

Instantly share code, notes, and snippets.

@birinder-lobana
Last active December 30, 2022 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save birinder-lobana/238e02acb9801519deee6a3b3d2b1867 to your computer and use it in GitHub Desktop.
Save birinder-lobana/238e02acb9801519deee6a3b3d2b1867 to your computer and use it in GitHub Desktop.
Create a new trackable, dynamic QR Code
// Initiate the Openscreen node SDK
const { Openscreen } = require("@openscreen/sdk");
require('dotenv').config();
const os = new Openscreen().config({key: process.env.OS_API_KEY, secret: process.env.OS_API_SECRET});
// Obtain ProjectID from Openscreen Dashboard
const projectId = 'YOUR PROJECT ID';
async function main() {
// Create an asset for a new listing sign being hosted for 123 Main Street
const res = await os.project(projectId).assets().create({
name: 'Store Lineup',
description: 'Store Line up For Outlet Mall',
qrCodes: [{
intent: 'https://www.my-qrcode-app.com',
intentType: 'DYNAMIC_REDIRECT'
}]
});
// Returns a scannable QR Code image in png format
const { qrCodeId } = res.asset.qrCodes[0];
const qrCode = await os.qrCode(qrCodeId).get({format: 'png'})
await os.saveQrImageDataToFile(qrCode, 'my-dynamic-qr-code.png');
// View the new asset that you have created
console.log('Asset:', JSON.stringify(res, '',2));
}
main().catch((err) => {
console.error(err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment