Last active
December 30, 2022 20:41
-
-
Save birinder-lobana/238e02acb9801519deee6a3b3d2b1867 to your computer and use it in GitHub Desktop.
Create a new trackable, dynamic QR Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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