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
APICalendars.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:
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
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
Using the above access token, call the API:
- 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.
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.