Integrating Outlook Calendar API with Website
Outlook Calendar is part of Microsoft 365. The API is implemented through Microsoft Graph. Used in enterprise tools: appointment scheduling, meeting synchronization, employee availability display.
Microsoft Graph: Reading Events
import { Client } from '@microsoft/microsoft-graph-client';
const client = Client.initWithMiddleware({ authProvider: tokenCredentialAuthProvider });
async function getCalendarEvents(userId: string): Promise<Event[]> {
const response = await client
.api(`/users/${userId}/calendarView`)
.query({
startDateTime: new Date().toISOString(),
endDateTime: new Date(Date.now() + 7 * 86400000).toISOString(),
})
.select('subject,start,end,location,isAllDay')
.orderby('start/dateTime')
.get();
return response.value.map((e: any) => ({
id: e.id,
title: e.subject,
start: e.start.dateTime,
end: e.end.dateTime,
location: e.location?.displayName,
allDay: e.isAllDay,
}));
}
Creating Event
async function createEvent(userId: string, booking: Booking): Promise<string> {
const event = await client.api(`/users/${userId}/events`).post({
subject: booking.serviceName,
start: { dateTime: booking.startsAt, timeZone: 'Russian Standard Time' },
end: { dateTime: booking.endsAt, timeZone: 'Russian Standard Time' },
body: {
contentType: 'HTML',
content: `<p>Client: ${booking.customerName}</p><p>Phone: ${booking.phone}</p>`,
},
attendees: [{ emailAddress: { address: booking.customerEmail }, type: 'required' }],
isReminderOn: true,
reminderMinutesBeforeStart: 60,
});
return event.id;
}
Checking Available Time (FindMeetingTimes)
async function findAvailableSlots(userEmail: string, duration: number) {
return client.api('/me/findMeetingTimes').post({
attendees: [{ emailAddress: { address: userEmail }, type: 'required' }],
timeConstraint: {
timeslots: [{
start: { dateTime: new Date().toISOString(), timeZone: 'Russian Standard Time' },
end: { dateTime: new Date(Date.now() + 7 * 86400000).toISOString(), timeZone: 'Russian Standard Time' },
}],
},
meetingDuration: `PT${duration}M`,
});
}
Timeline
Reading events + creation via Graph API: 3–4 business days.







