Microsoft Graph API empowers developers to access Microsoft Cloud service resources, including the robust calendar functionality of Microsoft 365. Creating a calendar event via the API is a seamless process that streamlines scheduling and automation. Let's delve into the intricacies of using Microsoft Graph API to create calendar events.

Before we dive into the API specifics, ensure you have the necessary permissions. You'll need to grant 'Calendars.ReadWrite' or 'Calendars.ReadWrite.All' delegated permissions, or 'Calendars.ReadWrite' application permissions for the app to create events on behalf of users.

Understanding the Calendar API Endpoint
The Calendar API endpoint for creating events is '/me/events' for personal calendars and '/users/{id | userPrincipalName}/calendar/events' for calendar events on behalf of a user. To create an event, send a POST request to this endpoint with the event details in the request body.

Here's a basic example using cURL:
curl -X POST "https://graph.microsoft.com/v1.0/me/events" -H "Authorization: Bearer {token}" -H "Content-Type: application/json" -d "{\"subject\":\"Meeting\",\"startDateTime\":\"2022-01-01T08:00:34.2445094-07:00\",\"endDateTime\":\"2022-01-01T09:00:34.2445094-07:00\"}"
Required Properties for Creating an Event

To create a valid event, you must include the following required properties in the request body:
- subject: The title of the event.
- startDateTime: The start date and time of the event.
- endDateTime: The end date and time of the event.
These properties are mandatory, and the API will return an error if they are not included.

Optional Properties for Enhanced Event Details
Besides the required properties, you can include several optional properties to provide more details about the event:
- location: The physical location of the event (e.g., 'Conf Room 1').
- isOrganizer: A boolean value indicating if the authenticated user is the organizer of the event.
- attendees: An array of attendee objects, each containing an email address and optional display name.

Including these optional properties can help create more comprehensive and useful calendar events.
Creating Recurring Events




















Microsoft Graph API also supports creating recurring events, allowing you to schedule repeating meetings or appointments. To create a recurring event, include the recurrence property in the request body, along with the required and optional properties mentioned earlier.
Here's an example of creating a weekly recurring event using cURL:
curl -X POST "https://graph.microsoft.com/v1.0/me/events" -H "Authorization: Bearer {token}" -H "Content-Type: application/json" -d "{\"subject\":\"Weekly Meeting\",\"startDateTime\":\"2022-01-01T08:00:34.2445094-07:00\",\"endDateTime\":\"2022-01-01T09:00:34.2445094-07:00\",\"recurrence\":{\"pattern\":{\"type\":\"weekly\"},\"range\":{\"type\":\"noEnd\",\"frequency\":1}}}"
Understanding Recurrence Patterns
The recurrence property accepts an object containing the recurrence pattern and range. The pattern defines the frequency and type of recurrence, while the range specifies the duration of the recurrence series.
Microsoft Graph API supports various recurrence patterns, including daily, weekly, monthly, and yearly. You can also specify the days of the week, months, or weeks for more granular control over the recurrence pattern.
Now that you've learned how to create calendar events using Microsoft Graph API, it's time to explore the API's other features, such as updating, deleting, and responding to events. Happy coding!