how to edit recurrance events using microsoft graph api with the option to edit only this and following events,this event as shown in screenshot? - microsoft-graph-api

refer image for the type of edit option using microsoft graph api
var stfulltext = 'Eastern Standard Time'
var options = { method: 'PATCH',
url: 'https://graph.microsoft.com/v1.0/users/'+newArray[0].id+'/calendar/events/'+eventslist1[0].microsoft_id,
headers:
{ 'content-type': 'application/json',
authorization: 'Bearer '+accesstoken,
prefer: `outlook.timezone="${stfulltext}"` },
body:
{
"originalStartTimeZone": stfulltext,
"originalEndTimeZone": stfulltext,
"responseStatus": {
"response": "organizer",
"time": "0001-01-01T00:00:00Z"
},
"start": {
"dateTime": outlook_start_time,
"timeZone": stfulltext
},
"end": {
"dateTime": outlook_end_time,
"timeZone": stfulltext
},
"recurrence": {
"pattern": {
"type": "daily",
"interval": 1,
},
"range": {
"type": "endDate",
"startDate": followup,
"endDate": end_date
}
},
"reminderMinutesBeforeStart": 15,
"isOnlineMeeting": false,
"onlineMeetingProvider": "unknown",
"isReminderOn": true,
"hideAttendees": false,
"categories": []
},
json: true };
i tried like this but it is getting updated all events

Please try first to get the list of occurrences,by using get method
GET /users/{id | userPrincipalName}/events/{id}/instances?startDateTime={start_datetime}&endDateTime={end_datetime}
ref doc - https://learn.microsoft.com/en-us/graph/api/event-list-instances?view=graph-rest-1.0&tabs=http
Then use the Patch API to update the event by providing event_id of occurrences -
PATCH /users/{id | userPrincipalName}/calendar/events/{id}
ref doc - https://learn.microsoft.com/en-us/graph/api/event-update?view=graph-rest-1.0&tabs=http
Hope this helps
Thanks

Related

Adding Calendar Event using 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.

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.

Expanding singleValueExtendedProperty not working when retrieving Event details

I am trying to retrieve custom property value for an event using Microsoft Graph.
The custom property was created by an Outlook Office.js Add-ing
Here is request
/v1.0/me/events/{id}?$expand=singleValueExtendedProperties($filter=id eq 'String {00020329-0000-0000-C000-000000000046} Name myCusProp')
This returns a successful response from Graph but it does not return the singleValueExtendedProperty. The Outlook add-in, however, is still able to retrieve the property value from the same Event.
{
"#odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('{id}')/events/$entity",
"#odata.etag": "W/\"SdXmMkSN8kCNtzTsQ4x1lwAD7sMWVg==\"",
"id": "{id}",
"createdDateTime": "2019-09-30T10:12:34.110571Z",
"lastModifiedDateTime": "2019-09-30T10:23:57.8338159Z",
"changeKey": "SdXmMkSN8kCNtzTsQ4x1lwAD7sMWVg==",
"categories": [],
"originalStartTimeZone": "blah blah",
"originalEndTimeZone": "blah blah Standard Time",
"iCalUId": "040000008...EBBE4999DC5A61D31AC544",
"reminderMinutesBeforeStart": 15,
"isReminderOn": true,
"hasAttachments": false,
"subject": "WWW-002",
"bodyPreview": "rt",
"importance": "normal",
"sensitivity": "normal",
"isAllDay": false,
"isCancelled": false,
"isOrganizer": true,
"responseRequested": true,
"seriesMasterId": null,
"showAs": "busy",
"type": "singleInstance",
"webLink": "https://outlook.office365.com/owa/?itemid=AQMkADU2OWFjYTFjLWNkMGYtNDdlNS1hNDIxLWIxYjlmY...DqyJu%2FWyzJk6m5v0MbSs7lwcASdXmMkSN8kCNtzTsQ4x1lwAAAgENA...AD7q52owAAAA%3D%3D&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl": null,
"recurrence": null,
"responseStatus": {
"response": "organizer",
"time": "0001-01-01T00:00:00Z"
},
"body": {
"contentType": "html",
"content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\n<div>rt</div>\r\n</body>\r\n</html>\r\n"
},
"start": {
"dateTime": "2019-09-19T02:30:00.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2019-09-19T03:00:00.0000000",
"timeZone": "UTC"
},
"location": {
"displayName": "",
"locationType": "default",
"uniqueIdType": "unknown",
"address": {},
"coordinates": {}
},
"locations": [],
"attendees": [],
"organizer": {
"emailAddress": {
"name": "Info a",
"address": "name#domain.com"
}
}
}
----Update 1 - office.js code-----
This is office-js/outlook-add-in code reference above.
The custom property value can be read here without an issue.
const item = Office.context.mailbox.item;
item.loadCustomPropertiesAsync(asyncResult => {
if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
let customProps = asyncResult.value;
customProps.set("myCusProp", "google.com");
customProps.saveAsync(asyncResult => {
if (asyncResult.status == Office.AsyncResultStatus.Succeeded) {
item.loadCustomPropertiesAsync(asyncResult => {
const customProps = asyncResult.value;
const myCusProp = customProps.get("myCusProp");
})
}
});
}
});
From documentation:
id eq 'String {00020329-0000-0000-C000-000000000046} Name cecp-<add-in id from manifest>'
Instead of myCusProp use cecp-/* add-in id from manifest */
Add-in id is the guid from manifest, this response has a custom properties as JSON.

Fail to use Graph API to create events which is imported from Google

I import some events to my Outlook Calendar via an ics file which were created in Google Calendar. The import is a success, but I find these event objects are different from the other events I create via Outlook UI.
Using Graph Explorer I see that originalStartTimeZone and originalEndTimeZone in imported event are tzone://Microsoft/Custom and recurrenceTimeZone is an empty string.
{
"#odata.etag": "W/\"jQw3WvygBke/Eeuel/y+PAACnR0HFQ==\"",
"id": "AAMkADU2MzY5ODJlLWI2YjgtNDM5YS1iMWQzLTkxNWFlOTk3MjA3MABGAAAAAAAZitkJ2449ToBFAe4BGzZIBwCNDDda-KAGR78R656X-L48AAKczwuSAACNDDda-KAGR78R656X-L48AAKcz0NjAAA=",
"createdDateTime": "2019-03-11T12:58:33.1040062Z",
"lastModifiedDateTime": "2019-03-11T12:58:33.2340999Z",
"changeKey": "jQw3WvygBke/Eeuel/y+PAACnR0HFQ==",
"categories": [],
"originalStartTimeZone": "tzone://Microsoft/Custom",
"originalEndTimeZone": "tzone://Microsoft/Custom",
"iCalUId": "040000008200E00074C5B7101A82E0080000000000000000000000000000000000000000320000007643616C2D55696401000000336A6C61316A6773666C6B766D70666F766D6D7365686439647240676F6F676C652E636F6D00",
"reminderMinutesBeforeStart": 0,
"isReminderOn": false,
"hasAttachments": false,
"subject": "Every Tue.",
"bodyPreview": "",
"importance": "normal",
"sensitivity": "normal",
"isAllDay": false,
"isCancelled": false,
"isOrganizer": true,
"responseRequested": false,
"seriesMasterId": null,
"showAs": "busy",
"type": "seriesMaster",
"webLink": "https://outlook.office365.com/owa/?itemid=AAMkADU2MzY5ODJlLWI2YjgtNDM5YS1iMWQzLTkxNWFlOTk3MjA3MABGAAAAAAAZitkJ2449ToBFAe4BGzZIBwCNDDda%2FKAGR78R656X%2FL48AAKczwuSAACNDDda%2FKAGR78R656X%2FL48AAKcz0NjAAA%3D&exvsurl=1&path=/calendar/item",
"onlineMeetingUrl": null,
"responseStatus": {
"response": "organizer",
"time": "0001-01-01T00:00:00Z"
},
"body": {
"contentType": "html",
"content": "<html><head><meta name=\"Generator\" content=\"Microsoft Exchange Server\">\r\n<!-- converted from text -->\r\n<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style></head>\r\n<body>\r\n<font size=\"2\"><span style=\"font-size:11pt;\"><div class=\"PlainText\"> </div></span></font>\r\n</body>\r\n</html>\r\n"
},
"start": {
"dateTime": "2018-08-13T22:00:00.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2018-08-14T00:00:00.0000000",
"timeZone": "UTC"
},
"location": {
"displayName": "",
"locationType": "default",
"uniqueIdType": "unknown",
"address": {},
"coordinates": {}
},
"locations": [],
"recurrence": {
"pattern": {
"type": "weekly",
"interval": 1,
"month": 0,
"dayOfMonth": 0,
"daysOfWeek": ["tuesday"],
"firstDayOfWeek": "monday",
"index": "first"
},
"range": {
"type": "endDate",
"startDate": "2018-08-14",
"endDate": "2018-09-18",
"recurrenceTimeZone": "",
"numberOfOccurrences": 0
}
},
"attendees": [],
"organizer": {
"emailAddress": {
"name": "my#gsuite.com",
"address": "my#gsuite.com"
}
}
}
Besides, when I use this event object as the request body of Create Event API, it returns this error:
{
"error": {
"code": "TimeZoneNotSupportedException",
"message": "A valid TimeZone value must be specified. The following TimeZone value is not supported: ''.",
"innerError": {
"request-id": "69f1a5de-1dbe-4caa-a996-15dc9190380c",
"date": "2019-03-13T13:37:24"
}
}
}
Is this a bug with importing .ics files or is it a limitation of the API?
The answer is the same as I provided to your question Can't create a all-day repeated via Graph API:
You're posting the entire object, including several read-only properties. This will always result in a failure of some kind.
When working with Microsoft Graph (most any REST API actually), you should only submit the properties you want to set.
For the event above, you'd send something like this:
POST https://graph.microsoft.com/v1.0/me/events
{
"isReminderOn": false,
"subject": "Every Tue.",
"importance": "normal",
"sensitivity": "normal",
"showAs": "busy",
"body": {
"contentType": "html",
"content": "<html><head><meta name=\"Generator\" content=\"Microsoft Exchange Server\">\r\n<!-- converted from text -->\r\n<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style></head>\r\n<body>\r\n<font size=\"2\"><span style=\"font-size:11pt;\"><div class=\"PlainText\"> </div></span></font>\r\n</body>\r\n</html>\r\n"
},
"start": {
"dateTime": "2018-08-13T22:00:00.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2018-08-14T00:00:00.0000000",
"timeZone": "UTC"
},
"recurrence": {
"pattern": {
"type": "weekly",
"interval": 1,
"daysOfWeek": ["Tuesday"]
},
"range": {
"type": "endDate",
"startDate": "2018-08-14",
"endDate": "2018-09-18"
}
}
}
For future reference, there is also a published list supported time zones in the documentation.

Microsoft Graph delta: recurring calendar events returning incorrect start/end

I have an app that loads calendar items into a database, and needs to stay in sync with the given user's calendar. Unfortunately, when querying Microsoft Graph for a given date range using Delta tokens, the original event's data is being returned. However, if the Delta call is removed from the query, recurring events are returned as expected.
The call without Delta:
https://graph.microsoft.com/v1.0/me/calendarView?startDateTime=2018-06-26T00:00:00&endDateTime=2018-06-27T00:00:00&$select=id,subject,start,end
Returns:
{
"#odata.etag": "W/\"vDPrV1TQYUmam8nxPycXGwABJbtmSQ==\"",
"id": "AAMkADZhMjA2YTNmLTM0NDktNDYyNy05Njk2LTRjNThhMDZkZDBmOQFRAAgI1dr3wqKAAEYAAAAAY_l4isQ6OkOWdkEvK3rrDQcAvDPrV1TQYUmam8nxPycXGwAAAAABDQAAvDPrV1TQYUmam8nxPycXGwAAAtcOVAAAEA==",
"subject": "Daily recurring event",
"start": {
"dateTime": "2018-06-26T14:30:00.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2018-06-26T14:45:00.0000000",
"timeZone": "UTC"
}
}
However, when trying to add the "delta" call to the request using the same start/end dates, the event's ORIGINAL dates (and Id) are returned. Additionally, the SELECT columns are ignored, entirely.
The call with Delta:
https://graph.microsoft.com/v1.0/me/calendarView/delta?startDateTime=2018-06-26T00:00:00&endDateTime=2018-06-27T00:00:00&$select=id,subject,start,end
Returns:
{
"#odata.type": "#microsoft.graph.event",
"#odata.etag": "W/\"vDPrV1TQYUmam8nxPycXGwABJbtmSQ==\"",
"createdDateTime": "2017-04-19T15:02:38.8680605Z",
"lastModifiedDateTime": "2018-06-25T14:15:14.2194888Z",
"changeKey": "vDPrV1TQYUmam8nxPycXGwABJbtmSQ==",
"categories": [],
"originalStartTimeZone": "Eastern Standard Time",
"originalEndTimeZone": "Eastern Standard Time",
"iCalUId": "040000008200E00074C5B7101A82E0080000000050B9E76D2CF2D001000000000000000010000000831C6E0657580F44A0799E55EB5F2E49",
"reminderMinutesBeforeStart": 15,
"isReminderOn": true,
"hasAttachments": false,
"subject": "Daily recurring event",
"bodyPreview": "",
"importance": "normal",
"sensitivity": "normal",
"isAllDay": false,
"isCancelled": false,
"isOrganizer": false,
"responseRequested": true,
"seriesMasterId": null,
"showAs": "busy",
"type": "seriesMaster",
...
"id": "AAMkADZhMjA2YTNmLTM0NDktNDYyNy05Njk2LTRjNThhMDZkZDBmOQBGAAAAAABj6XiKxDo6Q5Z2QS8reusNBwC8M_tXVNBhSZqbyfE-JxcbAAAAAAENAAC8M_tXVNBhSZqbyfE-JxcbAAAC1w5UAAA=",
"responseStatus": {
"response": "accepted",
"time": "2017-04-19T15:02:00Z"
},
"body": {
"contentType": "html",
"content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta name=\"Generator\" content=\"Microsoft Exchange Server\">\r\n<!-- converted from rtf -->\r\n<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>\r\n</head>\r\n<body>\r\n<font face=\"Calibri\" size=\"2\"><span style=\"font-size:11pt;\">\r\n<div> </div>\r\n<div> </div>\r\n</span></font>\r\n</body>\r\n</html>\r\n"
},
"start": {
"dateTime": "2015-09-22T14:30:00.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2015-09-22T14:45:00.0000000",
"timeZone": "UTC"
},
"location": {
"displayName": "on your feet",
"locationType": "default",
"uniqueId": "on your feet",
"uniqueIdType": "private"
},
"locations": [
{
"displayName": "on your feet",
"locationType": "default",
"uniqueId": "on your feet",
"uniqueIdType": "private"
}
],
"recurrence": {
"pattern": {
"type": "weekly",
"interval": 1,
"month": 0,
"dayOfMonth": 0,
"daysOfWeek": [
"monday",
"tuesday",
"wednesday",
"thursday",
"friday"
],
"firstDayOfWeek": "sunday",
"index": "first"
},
"range": {
"type": "noEnd",
"startDate": "2015-09-22",
"endDate": "0001-01-01",
"recurrenceTimeZone": "Eastern Standard Time",
"numberOfOccurrences": 0
}
},
"attendees": [
{
"type": "required",
"status": {
"response": "none",
"time": "0001-01-01T00:00:00Z"
},
"emailAddress": {
"name": "Nunya Biz",
"address": "biz#markie.com"
}
}
],
"organizer": {
"emailAddress": {
"name": "Nunya Biz",
"address": "biz#markie.com"
}
}
},
Can anyone tell me how can I get the Delta query to return the recurring event's instance, as opposed to the "seriesMaster"?
Ah, I figured it out! The delta returns the seriesMaster, but also returns the instance details (occurrence) at the end. My bad for leaving it out of the results in the original post.
The missing link:
{
"#odata.type": "#microsoft.graph.event",
"#odata.etag": "W/\"DwAAABYAAAC8M+tXVNBhSZqbyfE/JxcbAAElu2ZJ\"",
"seriesMasterId": "AAMkADZhMjA2YTNmLTM0NDktNDYyNy05Njk2LTRjNThhMDZkZDBmOQBGAAAAAABj6XiKxDo6Q5Z2QS8reusNBwC8M_tXVNBhSZqbyfE-JxcbAAAAAAENAAC8M_tXVNBhSZqbyfE-JxcbAAAC1w5UAAA=",
"type": "occurrence",
"id": "AAMkADZhMjA2YTNmLTM0NDktNDYyNy05Njk2LTRjNThhMDZkZDBmOQFRAAgI1dr3wqKAAEYAAAAAY_l4isQ6OkOWdkEvK3rrDQcAvDPrV1TQYUmam8nxPycXGwAAAAABDQAAvDPrV1TQYUmam8nxPycXGwAAAtcOVAAAEA==",
"start": {
"dateTime": "2018-06-26T14:30:00.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2018-06-26T14:45:00.0000000",
"timeZone": "UTC"
}
},
Note that the "type" = "occurrence", and the "seriesMasterId" points back to the seriesMaster's Id field. This contains the correct start/end information for the event.

Resources