Internal Server Error in /me/calendar/getSchedule with Calendars.ReadWrite/Delegated permission

Thakur, Saumya 20 Reputation points
2025-05-28T07:10:12.16+00:00

I wish to obtain the schedules of other users using the /me/calendar/getSchedule endpoint. I have the following 2 queries:

  1. If I wish to use the /me/calendar/getSchedule endpoint, will Calendars.ReadWrite/Delegated permission be enough? Also, will it suffice for the /users/{id}/calendar/getSchedule endpoint as well?
  2. I want to understand the authorization token that I am supposed to use in both cases.

CURRENT SITUATION:

I used the /me/calendar/getSchedule on graphExplorer and it returns me a 200 response with the following permissions:
User's image

However, using the same access token from this request tab and hardcoding it in my code is giving a 500 Internal Server Error response. Can this be because of insufficient permissions? Or do you see any other issue? Further, I cannot always hardcode it so can I obtain the required token using the /token/ endpoint? Will I need to use the /authorise/ endpoint as well before? If so, how do I obtain the authorization code?

My request looks like the following:

public async getSchedule(id:string, eids: string[], startTime:string, endTime:string, timezone:string): Promise
Microsoft Security | Microsoft Entra | Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Rukmini 3,841 Reputation points Microsoft External Staff Moderator
    2025-05-30T10:51:11.6566667+00:00

    Hello @Thakur, Saumya,

    Yes, Delegated Calendars.ReadWrite permission is enough to call /me/calendar/getSchedule and /users/{id}/calendar/getSchedule. But only if:

    • The signed-in user has access to the target calendars (via sharing or same tenant).
    • Otherwise, if the signed in user do not access to another user calendar, then to call /users/{id}/calendar/getSchedule API Calendars.ReadWrite application type API permission must be granted to the Micrsoft Entra ID application.
    • If using Calendars.ReadWrite application type API permission, then you need to make use of client credential flow to generate the access token.

    If you are passing the same token from Microsoft Graph Explorer in the code, then make sure to pass the token like below:

    - Make sure that the token is not expired.

    
    public async getSchedule(
    
      accessToken: string, // Pass the token here
    
      eids: string[],
    
      startTime: string,
    
      endTime: string,
    
      timezone: string
    
    ): Promise<any> {
    
      return await new Promise<any>((resolve, reject) => {
    
        request.post({
    
          url: `https://graph.microsoft.com/v1.0/me/calendar/getSchedule`,
    
          headers: {
    
            Authorization: `Bearer ${accessToken}`, 
    
            'Prefer': `outlook.timezone="${timezone}"`,
    
            'Content-type': 'application/json',
    
          },
    
          json: true,
    
          body: {
    
            schedules: eids,
    
            startTime: {
    
              dateTime: startTime,
    
              timeZone: timezone,
    
            },
    
            endTime: {
    
              dateTime: endTime,
    
              timeZone: timezone,
    
            },
    
            availabilityViewInterval: 60,
    
          },
    
        }, (error, response, body) => {
    
          if (error) {
    
            reject(error);
    
          } else {
    
            resolve(body);
    
          }
    
        });
    
      });
    
    }
    
    

    You can get the access token using Authorization code flow like below:

    Grant Calendars.ReadWrite permission to the Microsoft Entra ID application:

    User's image

    Use the authorize endpoint and generate the code by signing in the browser:

    
    https://login.microsoftonline.com/TenantID/oauth2/v2.0/authorize?
    
    &client_id=ClientID
    
    &response_type=code
    
    &redirect_uri=RedirectURL
    
    &response_mode=query
    
    &scope=https://graph.microsoft.com/.default
    
    &state=12345
    
    

    User's image

    Generate the access token and pass the code value from browser:

    
    https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
    
    client_id: ClientID
    
    grant_type: authorization_code
    
    scope: https://graph.microsoft.com/.default
    
    redirect_uri: RedirectURL
    
    code: codefromabove
    
    client_secret: Secret
    
    

    User's image

    Using the above access token, call the API:

    User's image

    • Pass the access token in the Headers as Authorization: Bearer xxxxYourTokenxxx.

    Reference:

    calendar: getSchedule - Microsoft Graph v1.0 | Microsoft Learn

    Hope this helps!


    If this answers your query, do click Accept Answer and Yes for was this answer helpful, which may help members with similar questions.

    User's image

    If you have any other questions or are still experiencing issues, feel free to ask in the "comments" section, and I'd be happy to help.


1 additional answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.