Reputation: 423
I have developed a Mobile Device Management application using the Google Android Management API in Node.js. The application was working properly, but now I am facing a 404 not found error when I create an enrollment token with the QR code. Can you suggest a solution to resolve this issue?
here is the code
const createEnrollmentToken = async (req,res,policyId) => {
try {
if (global.collectionExists) {
console.log(`Collection already exists. Data will not be stored.`);
} else {
// Qr Code Exapraition time setting for 1000 years
const durationInYears = 1000;
const secondsInYear = 365.25 * 24 * 60 * 60; // 365.25 days in a year to account for leap years
const durationInSeconds = durationInYears * secondsInYear;
const enrollmentToken = await androidManagementClient.enterprises.enrollmentTokens.create({
parent: global.enterpriseName,
requestBody: {
policyName: policyId,
duration: `${durationInSeconds}s`,
}
});
console.log('Enrollment token created successfully:', enrollmentToken.data);
try {
/* qr image */
const policies = await PoliciesDataModel.find({ username: global.adminUserName, "Polices.policyName": req.body.policyId });
if (policies && policies.length > 0) {
const image = {
'cht': 'qr', //cht represents the type of the chart or image, and its value is set to 'qr'.
'chs': '320x320', //chs specifies the size of the chart or image, and its value is set to '500x500', indicating a width and height of 500 pixels each.
'chl': enrollmentToken.data.qrCode //chl is the URL or data for the chart or image, and its value is taken from enrollmentToken.data.qrCode.
};
console.log(enrollmentToken.data.qrCode )
const qrcodeImgUrl = 'https://chart.googleapis.com/chart?' + querystring.stringify(image);
console.log('qrcodeImgUrl : ', qrcodeImgUrl)
const qrDoc = {
QrcodeImg: qrcodeImgUrl,
expiredDateTime: enrollmentToken.data.expirationTimestamp
};
} else {
// If no policies were found, send a not found response
console.log('No policies found for the given email and policy name.');
await res.redirect('/provision-Template');
}
} catch (error) {
console.log("Update Error", error)
}
// expiredDateTime: enrollmentToken.data.expirationTimestamp
await res.redirect('/provision-Template');
}
} catch (error) {
console.error('Error creating enrollment token:', error.message);
}
};
Upvotes: 2
Views: 2210
Reputation: 145
The https://chart.googleapis.com/chart?cht=qr api had been deprecated for years, and has now finally been taken down. You'll need to find a different way to generate a QR code. I'd advise you to use one of the many qr code generating libraries available instead of relying on an api because:
You can consider using https://github.com/nayuki/QR-Code-generator.
Upvotes: 1