Created
May 2, 2022 20:01
-
-
Save birinder-lobana/4437605316ebbc4369bcdda8e8b20042 to your computer and use it in GitHub Desktop.
Create a static 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 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' | |
// Generate your first Static QR Code | |
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