Adding Calendar Event using Microsoft Graph API - microsoft-graph-api

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.

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.

Related

Graph API calendar endpoint doesn't support sending Adaptive card as attachment

We are using https://graph.microsoft.com/v1.0/me/calendar/events for creating Calendar events. What we are trying to achieve additionally is to send an adaptive card as attachment. We are using below code as POST body
{
"subject": null,
"body": {
"contentType": "html",
"content": "<attachment id=\"74d20c7f34aa4a7fb74e2b30004247c5\"></attachment>"
},
"attachments": [
{
"id": "74d20c7f34aa4a7fb74e2b30004247c5",
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": null,
"content": "{\"$schema\":\"http://adaptivecards.io/schemas/adaptive-card.json\",\"version\":\"1.5\",\"type\":\"AdaptiveCard\",\"body\":[{\"type\":\"Container\",\"style\":\"emphasis\",\"items\":[{\"type\":\"TextBlock\",\"text\":\"TheEYorganizationtodayannouncesthedetailsofthe52womenfounders\",\"wrap\":true},{\"type\":\"ColumnSet\",\"columns\":[{\"style\":\"default\",\"width\":\"stretch\",\"items\":[{\"type\":\"ColumnSet\",\"columns\":[{\"items\":[{\"type\":\"Image\",\"width\":\"200px\",\"url\":\"https://tse3.mm.bing.net/th/id/OIP._awI5wQIVTy1k8QdHtpSWQHaEK?w=292&h=180&c=7&r=0&o=5&dpr=1.3&pid=1.7\"}],\"type\":\"Column\",\"width\":\"auto\"},{\"items\":[{\"type\":\"TextBlock\",\"size\":\"Medium\",\"weight\":\"Bolder\",\"text\":\"SomeText\",\"wrap\":true},{\"type\":\"TextBlock\",\"size\":\"Medium\",\"weight\":\"Bolder\",\"text\":\"[https://adaptivecards.io](https://adaptivecards.io)\",\"wrap\":true}],\"type\":\"Column\",\"width\":\"auto\"}]}],\"minHeight\":\"100px\",\"type\":\"Column\"}]}]}]}",
"name": null,
"thumbnailUrl": null
}
],
"start": {
"dateTime": "2022-11-18T12:00:00",
"timeZone": "Pacific Standard Time"
},
"end": {
"dateTime": "2022-11-18T12:30:00",
"timeZone": "Pacific Standard Time"
},
"location": {
"displayName": "Harry's Bar"
},
"attendees": [
{
"emailAddress": {
"address": "xero.01234#contoso.com",
"name": "Orex"
},
"type": "required"
}
],
"isOnlineMeeting": true,
"onlineMeetingProvider": "teamsForBusiness"}
Using above body, I am getting below error
{
"error": {
"code": "UnableToDeserializePostBody",
"message": "were unable to deserialize "
}}
As I understand this has something to do with the JSON I am passing as content inside attachment, I want to know if calendar invites endpoint supports adaptive card or not or is there any way, we can send adaptive card (using .NET SDK) to mail or events in outlook
Thanks, in advance
You can send actionable messages via emails only, see Supported scenarios for more information.

Schema Extensions Microsoft Graph API

Env: Developer Account aka using sandbox and through graph explorer.
I am having trouble updating a custom field added through schemaExtensions. Here are the steps:
POST https://graph.microsoft.com/v1.0/schemaExtensions
{
"id": {schemaName},
"description": "Meta data",
"targetTypes": [
"Event"
],
"owner": {app_id},
"properties": [
{
"name": "Pid",
"type": "String"
}
]
}
I get a 201 response:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#schemaExtensions/$entity",
"id": "extiv30x2jc_{schemaName}",
"description": "Meta data",
"targetTypes": [
"Event"
],
"status": "InDevelopment",
"owner": {app_id},
"properties": [
{
"name": "Pid",
"type": "String"
}
]
}
I then create a event as below:
POST https://graph.microsoft.com/v1.0/me/events
{
"subject": "My event",
"start": {
"dateTime": "2021-02-25T22:45:11.110Z",
"timeZone": "UTC"
},
"end": {
"dateTime": "2021-02-25T22:45:11.110Z",
"timeZone": "UTC"
}
}
Event is successfully created and I note the id of the event. I then patch the event, since it is not possible to create an instance and update the custom field simultaneously.
PATCH https://graph.microsoft.com/v1.0/me/events/{id}
{
"extiv30x2jc_{schemaName}": {
"Pid": "1"
}
}
For which I get a 200 response like below:
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users({graph_explorer_profile_id})/events/$entity"
}
To search for the event to see if the custom field has been updated, i use this:
GET https://graph.microsoft.com/v1.0/me/events/{id}
But I cannot find the custom field Pid. What did I do wrong here?
Regarding
But I cannot find the custom field Pid. What did I do wrong here?
by default schema extensions are not getting returned. Use select parameter to return schema extension along with default event properties:
GET https://graph.microsoft.com/v1.0/me/events/{id}?$select=extiv30x2jc_{schemaName}
Try to call this endpoint:
GET https://graph.microsoft.com/v1.0/me/events/{id}/extensions

Microsoft Graph API creating recurring event returns 500

I'm writing an app that synchronizes with Office365's events using the Microsoft Graph API v1.0.
When creating a single event, the event gets created as expected:
Response Status Code: 201 Created
Request URL: https://graph.microsoft.com/v1.0/me/calendars/<myCalendarId>/events
Request Method: POST
Request Payload:
{
"subject": "single event",
"start": {
"dateTime": "2020-02-15T09:00:00",
"timeZone": "Europe/Berlin"
},
"end": {
"dateTime": "2020-02-15T10:00:00",
"timeZone": "Europe/Berlin"
},
"attendees": [],
"type": "singleInstance",
"location": {
"displayName": null
},
"recurrence": null
}
If, however, I send a create request for a recurring event, I get a error response.
Response Status Code: 500 Internal Server Error
Request URL: https://graph.microsoft.com/v1.0/me/calendars/<myCalendarId>/events
Request Method: POST
Request Payload:
{
"subject": "test recurring event",
"start": {
"dateTime": "2020-02-14T09:00:00",
"timeZone": "Europe/Berlin"
},
"end": {
"dateTime": "2020-02-14T10:00:00",
"timeZone": "Europe/Berlin"
},
"attendees": [],
"location": {
"displayName": null
},
"recurrence": {
"pattern": {
"daysOfWeek": [],
"type": "daily"
},
"range": {
"numberOfOccurrences": "2",
"recurrenceTimeZone": "Europe/Berlin",
"startDate": "2020-02-14",
"type": "numbered"
}
}
}
Response Body:
{
"error": {
"code": "ErrorInternalServerError",
"message": "An internal server error occurred. The operation failed.",
"innerError": {
"request-id": "2d97931c-e08c-45a8-8167-5849df53a694",
"date": "2020-02-14T14:38:28"
}
}
}
I find it strange that the addition of the recurrence settings causes an Internal Server Error.
What can I do to create a recurring event with the API?
If you want to create a recurring event that occurs daily, instead of setting pattern in the following way:
"pattern": {
"daysOfWeek": [],
"type": "daily"
},
Please set pattern this way:
"pattern": {
"type": "daily",
"interval": 1
},
Creating a daily recurrence pattern is described here in the conceptual docs. Within the next day, there will also be a REST example in the reference docs.

Outlook event RSVP graph api issue

Created an Event with Microsoft Graph:
{
"subject": "TEST",
"body": {
"contentType": "HTML",
"content": "test event respond"
},
"start": {
"dateTime": "2019-05-22T00:00:00",
"timeZone": "Asia/Kolkata"
},
"end": {
"dateTime": "2019-05-22T00:00:00",
"timeZone": "Asia/Kolkata"
},
"location": { "displayName": "Leena AI" },
"attendees": [
{
"emailAddress": {
"address": "sachin#live.com",
"name": "Sachin Goel"
},
"type": "optional"
}
],
"isReminderOn": false,
"reminderMinutesBeforeStart": 15
}
If I try to accept the event from sachin#live.com user it throws an error:
{
"error": {
"code": "ErrorItemNotFound",
"message": "The specified object was not found in the store.",
"innerError": {
"request-id": "485528b0-dbbe-42f5-80c0-5fc91477fc31",
"date": "2019-04-30T07:11:58"
}
}
}
sample request:
https://graph.microsoft.com/v1.0/me/events/{eventId}/accept
{
"comment" : "respond from api"
}
It results in NotFoundError but this works from UI. I have tried different solution (updating permission, primary calendar) but nothing works
Are there any constraints with this flow at the API level?
The Event ID for the Event you created in your mailbox is not going to be the same as the Event ID in the sachin#live.com mailbox.
You need to find the message with the sachin#live.com mailbox and then accept that id.

Are the organizer and isOrganizer Attributes in MS-Graph event working?

I'm trying to use the MS Graph API to create a new event with a technical user on behalf of a resource. The event is created, but the organizer and isOrganizer Attributes are not considered or ignored in the response.
I tried multiple requests as well as in 'v1.0' and 'beta' mode. In this SO question How to create event where current user not organizer using Microsoft Graph API it is stated that this is not implemented at the time of the original post (2016). But I didn't find anything in the Graph-API docs, saying that this would not work.
This is the request body:
{
"subject": "Instant Meeting: " + user_name,
"body": {
"contentType": "HTML",
"content": "Dieser Termin wurde vom Konferenzraum eingestellt"
},
"isOrganizer": "false",
"organizer" : {
"emailAddress": {
"address":user_email,
"name": user_name
}
},
"start": {
"dateTime": start,
"timeZone": "Europe/Berlin"
},
"end": {
"dateTime": end,
"timeZone": "Europe/Berlin"
},
"location":{
"displayName": room.get('name'),
"locationEmailAddress": room.get('email'),
"locationType" : "conferenceRoom"
},
"attendees": [
{
"emailAddress": {
"address":user_email,
"name": user_name
},
"type": "required"
},
{
"emailAddress": {
"address":room.get('email'),
"name": room.get('name')
},
"type": "resource"
}
]
}
The relevant parts of the response are:
response.get('organizer')
{'emailAddress': {'address': 'testraum-nichtbuche...t-mail.de', 'name': 'TestRaum - NICHT BUCHEN'}}
'emailAddress': {'address': 'testraum-nichtbuche...t-mail.de', 'name': 'TestRaum - NICHT BUCHEN'}
__len__: 1
response.get('isOrganizer')
True
If this worked properly, I would expect the 'organizer' to be user_email and the flag to be set to False.
Can anyone provide a working example for this?
Thanks!
This behavior has not changed. The organizer and isOrganizer properties cannot be defined by the caller, they are automatically assigned by Exchange:
setting event organizer with Outlook Calendar REST API
Outlook Calendar Rest API (create meeting using /me/events request with change organizer)
outlook.com rest api incorrect organizer email
How to create event where current user not organizer using Microsoft Graph API

Resources