Get Microsoft Graph API v1.0 Calendar Data
Ever needed to access your Outlook calendar via Microsoft Graph API? The endpoint https://graph.microsoft.com/v1.0/me/calendar is your gateway to managing and interacting with your own calendar data. Let's delve into how to use this endpoint effectively and efficiently.
Before we proceed, ensure you have the necessary permissions - 'Calendars.Read' or 'Calendars.ReadWrite.All' - and are authenticated with Microsoft Identity Platform. Your access token should be carrying these permissions.
Understanding the Calendar Endpoint
The me/calendar endpoint retrieves the signed-in user's calendar. It's a collection of events that the user has created, owns, or has been invited to.
To interact with this data, you can use various HTTP methods: GET for retrieval, POST for creation, PATCH for updates, and DELETE for removal. Let's explore these methods with some commonly used sub-topics.
Retrieving Calendar Events (GET)
You can fetch all calendar events using the GET method:
GET https://graph.microsoft.com/v1.0/me/calendar
To fetch events within a specific time range, use the $filter query parameter:
GET https://graph.microsoft.com/v1.0/me/calendar?$filter=start/datetime ge 2022-01-01T00:00:00Z and end/datetime le 2022-12-31T23:59:59Z
Creating a New Calendar Event (POST)
To add a new event, set the Graph API's request body with the event details:
POST https://graph.microsoft.com/v1.0/me/calendar
Content-type: application/json
{
"subject": "Calendar event",
"startDateTime": "2022-02-01T09:00:34.2445117-07:00",
"endDateTime": "2022-02-01T10:00:34.2445117-07:00",
"isOrganizer": true
}
Managing Calendar Event Invitations
Outlook calendar events often involve invitees. Microsoft Graph API allows you to manage these invitations with the me/calendar events/{id}/attendees endpoint.
Here, you can add, remove, or update attendees. You can also query attendee status (e.g., 'accepted', 'tentative', 'declined', 'noResponse').
Adding Attendees to an Event (POST)
To invite attendees to an existing event, POST to me/calendar events/{id}/attendees:
POST https://graph.microsoft.com/v1.0/me/calendar/events/{id}/attendees
Content-type: application/json
{
"@odata.id": "mailto:attendee@example.com",
"type": "required",
"status": {
"response": "none"
}
}
Querying Attendee Responses
Retrieve attendee responses using GET:
GET https://graph.microsoft.com/v1.0/me/calendar/events/{id}/attendees?$select=status
Effectively using the https://graph.microsoft.com/v1.0/me/calendar endpoint allows you to streamline your Outlook calendar management. Stay organized and productive with these robust, flexible API capabilities. Now dive in and make the most of Microsoft Graph API!