Skip to content

Instantly share code, notes, and snippets.

@birinder-lobana
Last active September 8, 2022 14:27
Show Gist options
  • Save birinder-lobana/2f67737c3a8d0d4578c8dd71c0f77cc6 to your computer and use it in GitHub Desktop.
Save birinder-lobana/2f67737c3a8d0d4578c8dd71c0f77cc6 to your computer and use it in GitHub Desktop.
Use this code to create contacts upon scanning a dynamic QR code.
// Initiate the Openscreen node SDK and include the project ID that you received 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 a new contact
const create_contact_by_project_id = await os.project(projectId).contacts().create({
firstName: "Brian",
lastName: "Smith",
emailAddress: "bsmith@test.com",
cellPhone: "+11234567890",
mailingAddress: {
address: "123 Street",
city: "Toronto",
provinceOrState: "ON",
country: "Canada",
postalOrZip: "A1B2C3"
},
customAttributes: {
campaign: "Toronto June listings"
}
consent: [{
url: ["https://sidewalkqr.com/terms-and-conditions", "abc.com/terms-and-conditions"],
consentedAt: "2021-06-20 08:03:00.0",
consentStatus: "ACCEPTED",
consentType: "SMS",
projectId: projectId,
},
{
url: ["https://sidewalkqr.com/terms-and-conditions", "abc.com/terms-and-conditions"],
consentedAt: "2021-06-20 08:03:00.0",
consentStatus: "DECLINED",
consentType: "CUSTOM",
projectId: projectId,
}]
})
// View the new contact that you have created
console.log('Contact:', JSON.stringify(contact, '',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