Create event as non admin user using Microsoft Graph

Gleitze Ramos 1 Reputation point
2022-03-24T16:00:21.007+00:00

Hello!

Im creating an app to create events in a Business Platform using Mircrosoft graph , everything works fine I can create , modify and delete events if I do the request as admin user (https://graph.microsoft.com/v1.0/**me**/event), but if I use some users Principal Name instead of "me" I get the following Error : {"Remote Server Error: (400) Bad Request."}, I tried using users id and I got the same response.

I reviewed permissions on Azure directory platform and I granted the required permission that Microsoft documentation states, everything looks ok.

Hope you can help me, thanks in advance!

Microsoft Security Microsoft Graph
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. JanardhanaVedham-MSFT 3,566 Reputation points
    2022-03-24T18:37:31.767+00:00

    Hi @Gleitze Ramos ,

    You would need to use the below Microsoft Graph Calendar API to create the events with "Calendars.ReadWrite" graph API application permissions granted to your app in Azure AD. Please make sure to mention /users and then followed by User ID or userPrincipalName in the API as mentioned below. Also, I have tested it and the events are created for other non-admin users or general users with the below mentioned API & sample JSON payload (as shown in the below screenshot) and you can also verify the same.

    Also, regarding your requirement , you would have to register an application (i.e, a background service or daemon that run on a server without the presence of a signed-in user) in Azure AD. This app can call Microsoft Graph with their own identity use the OAuth 2.0 client credentials grant flow to get access tokens from Azure AD. You can refer documentation for more details information on Authentication and authorization steps.

    POST https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/events  
    POST https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/calendar/events  
    POST https://graph.microsoft.com/v1.0/users/{id | userPrincipalName}/calendars/{id}/events  
    

    Example :

    POST https://graph.microsoft.com/v1.0/users/******@o365XXX.onmicrosoft.com/events  
    {  
        "subject": "Let's go for lunch",  
        "body": {  
            "contentType": "HTML",  
            "content": "Does noon work for you?"  
        },  
        "start": {  
            "dateTime": "2022-03-25T12:00:00",  
            "timeZone": "Pacific Standard Time"  
        },  
        "end": {  
            "dateTime": "2022-03-25T14:00:00",  
            "timeZone": "Pacific Standard Time"  
        },  
        "location": {  
            "displayName": "Harry's Bar"  
        },  
        "attendees": [  
            {  
                "emailAddress": {  
                    "address": "******@contoso.onmicrosoft.com",  
                    "name": "Samantha Booth"  
                },  
                "type": "required"  
            }  
        ]  
    }  
    

    **Example Output in Postman : An event is created in non-admin/general user's calendar ** :

    186500-image.png

    You can refer the below documentation on create events using Microsoft Graph Calendar API :

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

    Hope this helps.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have any further questions about this answer, please click "Comment".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.