User can view and edit calendar, but not create events

Matthew Wetmore 0 Reputation points
2024-04-15T19:02:52.1866667+00:00

I am attempting to use the MS Graph API to create a calendar event on a calendar, using the following endpoint:

https://graph.microsoft.com/v1.0/me/calendars/<calendar_id>/events

I am passing a valid OAuth access token using the Authorization header. When I POST to this endpoint with the following body:


{
    "start": {
        "dateTime": "2024-04-16T13:00",
        "timeZone": "America/Los_Angeles"
    },
    "end": {
        "dateTime": "2024-04-16T13:30",
        "timeZone": "America/Los_Angeles"
    },
    "subject": "<omitted>",
    "body": {
        "content": "<omitted>",
        "contentType": "HTML"
    },
    "sensitivity": "Normal",
    "attendees": [
        {
            "emailAddress": {
                "address": "<omitted>"
            },
            "type": "required"
        },
        {
            "emailAddress": {
                "address": "<omitted>"
            },
            "type": "required"
        }
    ],
    "locations": [],
    "transactionId": "<random uuid>"
}

I get the following 404 error back:

{"error": {"code": "ErrorItemNotFound", "message": "The specified object was not found in the store."}}

This suggested to me that the problem was that the user does not have access to the calendar. However, if I submit a GET request to the same events endpoint, using the same calendar ID in the URL, I get back a list of events with no error.

If I submit a GET request to https://graph.microsoft.com/v1.0/me/calendars/<calendar_id>, I get the following response:

{
    "@odata.context": "<omitted>",
    "id": "<calendar_id>",
    "name": "<omitted>",
    "color": "auto",
    "hexColor": "",
    "isDefaultCalendar": false,
    "changeKey": "<omitted>",
    "canShare": true,
    "canViewPrivateItems": true,
    "canEdit": true,
    "allowedOnlineMeetingProviders": [],
    "defaultOnlineMeetingProvider": "unknown",
    "isTallyingResponses": true,
    "isRemovable": true,
    "owner": {
        "name": "<omitted>",
        "address": "<omitted>"
    }
}

How can I fix this, so I can create a new event, instead of getting a 404?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,625 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Patchfox 3,786 Reputation points
    2024-04-15T19:18:36.3166667+00:00

    Hi, Matthew Wetmore I want to help you with this question.

    As I understand, you want to create an event via Graph API, but with the POST Request you get the error response shown in the screenshot, right?

    As you assume it looks like a permission problem.

    Please check the permissions of the service principal (app registration) if you have set the following permissions and they are consented.

    Calendar Delegated (work or school account) Delegated (personal Microsoft account) Application
    user calendar Calendars.ReadWrite Calendars.ReadWrite Calendars.ReadWrite

    Please consider that the group calendars can only be chosen by the Delegated (work or school account)

    See also: https://learn.microsoft.com/en-us/graph/api/calendar-post-events?view=graph-rest-1.0&tabs=http

    Additionally, check that you have a valid bearer token. But I think everything is fine with it. You would get another error message rather.


    If the reply was helpful, please don’t forget to upvote or accept it as an answer, thank you!