Skip to content

Instantly share code, notes, and snippets.

@birinder-lobana
Created May 2, 2022 18:47
Show Gist options
  • Save birinder-lobana/d5547ecfb1bff736640090461f7149e1 to your computer and use it in GitHub Desktop.
Save birinder-lobana/d5547ecfb1bff736640090461f7149e1 to your computer and use it in GitHub Desktop.
Create a static QR code
// Initiate the Openscreen node SDK and include the project ID that you recieved using the Openscreen dashboard
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});
const projectId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
async function main() {
// Create an asset and generate a Static QR Code
const res = await os.project(projectId).assets().create({
name: 'My First Static QR Code',
qrCodes: [{
intent: `https://openscreen.com`,
intentType: 'STATIC_REDIRECT'
}]
});
const { qrCodeId } = res.asset.qrCodes[0];
// Returns a scannable QR Code and saves the png file in your project folder
const qrCode = await os.qrCode(qrCodeId).get({format:'png', dataUrl: true});
await os.saveQrImageDataToFile(qrCode, 'my-static-qr-code.png');
// Returns the Openscreen qrCode object
console.log("QR Code:", JSON.stringify(qrCode, '',2));
}
main().catch(err => {
console.log(JSON.stringify(err, ' ', 2))
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment