0

I am trying to create an event in a calendar from a Powershell script. It needs to add the calendar event to the organizer's calendar and then to a list of attendees. Below is what I am sending in the body of the request.

{
  "subject": "Let's go for lunch",
  "IsOrganizer": "true",
  "body": {
    "contentType": "HTML",
    "content": "Does noon work for you?"
  },
  "start": {
      "dateTime": "2020-08-31T12:00:00",
      "timeZone": "Pacific Standard Time"
  },
  "end": {
      "dateTime": "2020-08-31T14:00:00",
      "timeZone": "Pacific Standard Time"
  },
  "location":{
      "displayName":"Harry's Bar"
  },
  "attendees": [
    {
      "emailAddress": {
        "address":"attendee1@attendeeadress.com",
        "name": "Attendee1"
      },
      "type": "required",
       "status": {
                "response": "none",
                "time": "0001-01-01T00:00:00Z"
        }
    },
      {
      "emailAddress": {
        "address":"attendee2@attendeeadress.com",
        "name": "Attendee2"
      },
      "type": "required",
       "status": {
                "response": "none",
                "time": "0001-01-01T00:00:00Z"
        }
    }
  ],
   "organizer":{
        "emailAddress":{
            "name":"Specific Calendar",
            "address":"calendarname@organizerorganization.onmicrosoft.com"
        }
    },
  "allowNewTimeProposals": true
}

It appears successfully on the calendar of the attendees but not on the main organizer's calendar. Can anyone tell me what I am doing wrong and how I can get this to appear on the main organizer's calendar?

Thanks!

UPDATE - This is how I am getting the user token.

$Body = @{
    'client_id' = 'my_client_id'
    'scope' = 'https://graph.microsoft.com/.default'
    'client_secret' = 'my_client_secret'
    'grant_type' = 'password'
    'userName' = 'calendarname@organizerorganization.onmicrosoft.com'
    'password' = 'password'
}

It is now my understanding that this user should be set as the organizer of an event by default.

MountainBiker
  • 327
  • 5
  • 20
  • Looks like you are trying to create an event and give organizer as a different person. The organizer cannot be defined by caller. Please go through this [document](https://stackoverflow.com/questions/56165042/are-the-organizer-and-isorganizer-attributes-in-ms-graph-event-working). – Shiva Keshav Varma Sep 14 '20 at 12:43
  • I'm not though. My user is calendarname@organizerorganization.onmicrosoft.com so from what I understand, that should be the organizer by default? I tried adding that email as an attendee to see if it would appear on the calendar and it didn't. It appears on the calendars of the other attendees I supply. This makes me think it may by a permissions issue and not something in the body of my request... – MountainBiker Sep 14 '20 at 18:47
  • Yes, so if you create an event with a delegated token of calendarname@organization.onmicrosoft.com the one who creates the event will be the organizer. Here it should be your calendarname@organization.onmicrosoft.com. Please go through the above thread which I shared, will give you the clear picture. – Shiva Keshav Varma Sep 15 '20 at 16:43
  • I thought I was. I am new to the Graph API so forgive my ignorance... I have updated my original question to show how I am getting the user token. – MountainBiker Sep 15 '20 at 21:03
  • I have tested it using postman with the same token how you got using ROPC flow and used the call `POST https://graph.microsoft.com/v1.0/me/calendar/events`. Please try it and see if it helps. – Shiva Keshav Varma Sep 16 '20 at 12:21
  • Did it work for you? – Shiva Keshav Varma Sep 21 '20 at 08:10
  • It turned out to be a permissions issue with writing the that calendar. One last question, I can write events to the calendar in the future but it won't let me write events to dates in the past. Is there a setting that would allow me to do that? – MountainBiker Sep 22 '20 at 23:44
  • No you cannot modify the already finished events by updating the 'start' and 'end' properties. – Shiva Keshav Varma Sep 23 '20 at 10:38

1 Answers1

1

You can create an event using ROPC flow which gives you the user access token and using it you can call the /events endpoint with your payload as shown below.

POST https://graph.microsoft.com/v1.0/me/calendar/events

If you create an event with this token and give username as calendarname@organization.onmicrosoft.com this will be the organizer of the event.

And you can update 'subject', 'body/content' but you cannot update the event's 'start' and 'end' properties which is already a finished event.

Shiva Keshav Varma
  • 3,398
  • 2
  • 9
  • 13