How to integrate in outlook calendar in nodejs.
I have refered from Set Microsoft Calendar(Microsoft 365) With NodeJs in Medium Blog,
but its not working.
Can anyone help me to solve this issue
Loading
How to integrate in outlook calendar in nodejs.
I have refered from Set Microsoft Calendar(Microsoft 365) With NodeJs in Medium Blog,
but its not working.
Can anyone help me to solve this issue
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jithu ThomasRank #437 · 5.7K reputationPosted Nov 25, 2023, 6:05 AM EST
Register Your App:
Calendars.ReadWritefor calendar access).Install Necessary Packages:
Code Sample-
const express = require('express'); const axios = require('axios'); const msal = require('@azure/msal-node'); const app = express(); const config = { auth: { clientId: 'YOUR_CLIENT_ID', authority: 'https://login.microsoftonline.com/YOUR_TENANT_ID', clientSecret: 'YOUR_CLIENT_SECRET', }, }; const cca = new msal.ConfidentialClientApplication(config); app.get('/login', (req, res) => { const authCodeUrlParameters = { scopes: ['openid', 'profile', 'offline_access', 'Calendars.ReadWrite'], redirectUri: 'http://localhost:3000/redirect', }; const authUrl = cca.getAuthCodeUrl(authCodeUrlParameters); res.redirect(authUrl); }); app.get('/redirect', async (req, res) => { const tokenRequest = { code: req.query.code, scopes: ['openid', 'profile', 'offline_access', 'Calendars.ReadWrite'], redirectUri: 'http://localhost:3000/redirect', }; try { const response = await cca.acquireTokenByCode(tokenRequest); const accessToken = response.accessToken; // Use the accessToken to make requests to Microsoft Graph API const apiUrl = 'https://graph.microsoft.com/v1.0/me/calendar/events'; const headers = { Authorization: `Bearer ${accessToken}`, }; const eventData = { // Your calendar event data here }; await axios.post(apiUrl, eventData, { headers }); res.send('Calendar event created successfully!'); } catch (error) { console.error(error); res.status(500).send('Error occurred during authentication.'); } }); const PORT = 3000; app.listen(PORT, () => { console.log(`Server is running on port ${PORT}`); });Replace
'YOUR_CLIENT_ID','YOUR_TENANT_ID', and'YOUR_CLIENT_SECRET'with your actual values.Note: Ensure that the redirect URI configured in your Azure app matches the URI specified in the code (
http://localhost:3000/redirectin this example).