Как я могу сделать этот вызов API? Этот код использует microsoft-graph-client для двух вызовов API. Первый звонок получит ID календаря, который я хочу. Второй использует идентификатор календаря, чтобы получить события этого календаря. Хотел бы иметь один вызов API. Вся документация, которую я прочитал до сих пор, не имеет возможности получать события календаря указанного календаря.
//// Modules used...
var authHelper = require('../helpers/auth'); //// used to get the access token
var graph = require('@microsoft/microsoft-graph-client');
...
//// Initialize Graph client with access token.
const client = graph.Client.init({
authProvider: (done) => {
done(null, accessToken);
}
});
//// Specify start and end times for second API call.
const start = new Date(new Date().setHours(0,0,0));
const end = new Date(new Date(start).setDate(start.getDate() + 30000));
/**
* Step 1
* Get all the calendar, then cut out the calendar id I need.
* STEP 2
* Get the events using the calendar id.
*/
const calendars = await client
.api('https://graph.microsoft.com/v1.0/me/calendars/')
.select('name,id')
.get();
/**
* Cut out the id of first calendar named 'School_Calendar' in the array of calendars.
*/
const c = calendars.value.find(obj => {
return obj.name === 'School_Calendar'
});
const calen_id = c.id;
/**
* Now use the Calendar's id to get the calendar's events.
*/
const api = `/me/calendars/${calen_id}/calendarView?startDateTime=${start.toISOString()}&endDateTime=${end.toISOString()}`;
const result = await client
.api(api)
.select('subject,start,end')
.orderby('start/dateTime DESC')
.get();
//// print the events of School_Calendar
console.log(result.value;);