Geting 401 Unauthorised Access when accessing calendar using graph api

Shivam Sood 1 Reputation point

* Calls the endpoint with authorization bearer token.
* @Paramjeet Dahiya {string} endpoint
* @Paramjeet Dahiya {string} accessToken
async function callApi(endpoint, accessToken) {

const options = {  
    headers: {  
        Authorization: `Bearer ${accessToken}`  

console.log('request made to web API at: ' + new Date().toString());  

try {  
    const response = await axios.get(endpoint, options);  
    // console.log(`Response`,;  
    const temp = await axios.get(`${[0]['id']}/events`, options);  
} catch (error) {  
    return error;  


async function temp(){
let temp = await getToken(tokenRequest)
console.log(Temp -->,temp.accessToken);
// let endpoint = ''
// let endpoint = "'20d65521-105b-4ba8-bc47-2429e89cc5b2')/calendars"
let endpoint = ''
console.log(await callApi(endpoint,temp.accessToken))


Using This Code I Am Able To Extract The data from the endpoint /users but when i am passing a user id to /calendar api it showing me 401 unauthorised access error and idea why this is happening . i have also given all the permission related to calendar & user in my application

Microsoft Graph Calendar API
No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Gopinath Chennamadhavuni-MSFT 1,536 Reputation points Microsoft Vendor

    Hi @Shivam Sood ,

    Thank you for reaching out to us. As I see you are getting error 401 while performing GET /v1.0/users/{user-id}/calendars to Graph API.

    Error 401 is an Unauthorized error. Make sure that your application is presenting a valid access token to Microsoft Graph as part of the request. This error often means that the access token may be missing in the HTTP authenticate request header or that the token is invalid or has expired.

    We strongly recommend that you use the Microsoft Authentication Library (MSAL) for access token acquisition.

    Also, you can check your scopes by decoding access token in, make sure you have Calendars.Read, Calendars.ReadWrite permission added. Please refer the link for more details.

    For application permission token, the permissions are in the “roles” claim:

    For delegated permission token, the permissions are in the “scp” claim.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.

    No comments