问题
According to the document, I try to use Graph API to create a all-day repeated event on my calendar, but the server always responses 400: TimeZoneNotSupportedException.
Is there any wrong in my request?
Here is my request and server response.
POST /me/calendars/${one_of_my_calendar_id}/events
Request body:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('6cb879ad-1d01-4aed-bcc5-763e3f51c535')/events/$entity",
"@odata.etag": "W/\"BfXylo4WykyAenTZICXL5AABk4B1gA==\"",
"id": "AAMkADVmMzE2MjY0LTZkOGYtNGI4MS1iNWMxLTljYzg3MWY5MWQxMQBGAAAAAABZMfR36TVMQ6yunaqZPvVRBwAF9fKWjhbKTIB6dNkgJcvkAACB0WDVAAAF9fKWjhbKTIB6dNkgJcvkAAGTapeDAAA=",
"createdDateTime": "2019-03-07T10:25:29.5732546Z",
"lastModifiedDateTime": "2019-03-07T10:25:29.6573241Z",
"changeKey": "BfXylo4WykyAenTZICXL5AABk4B1gA==",
"categories": [],
"originalStartTimeZone": "UTC",
"originalEndTimeZone": "UTC",
"iCalUId": "040000008200E00074C5B7101A82E00800000000FB7128DC464BD4010000000000000000100000006176917542798940B4FDBBFBA5B474A6",
"reminderMinutesBeforeStart": 0,
"isReminderOn": false,
"hasAttachments": false,
"subject": "Repeat-",
"bodyPreview": "",
"importance": "normal",
"sensitivity": "normal",
"isAllDay": true,
"isCancelled": false,
"isOrganizer": true,
"responseRequested": false,
"seriesMasterId": null,
"showAs": "free",
"type": "seriesMaster",
"webLink": "https://outlook.office365.com/owa/?itemid=AAMkADVmMzE2MjY0LTZkOGYtNGI4MS1iNWMxLTljYzg3MWY5MWQxMQBGAAAAAABZMfR36TVMQ6yunaqZPvVRBwAF9fKWjhbKTIB6dNkgJcvkAACB0WDVAAAF9fKWjhbKTIB6dNkgJcvkAAGTapeDAAA%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-09-25T00:00:00.0000000",
"timeZone": "UTC"
},
"end": {
"dateTime": "2018-09-26T00: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-09-25",
"endDate": "2019-03-12",
"recurrenceTimeZone": "",
"numberOfOccurrences": 0
}
},
"attendees": [],
"organizer": {
"emailAddress": {
"name": "MYNAME",
"address": "MYNAME@MYMAIL.com"
}
} }
Server response: http code: 400
{
"error": {
"code": "TimeZoneNotSupportedException",
"message": "A valid TimeZone value must be specified. The following TimeZone value is not supported: ''.",
"innerError": {
"request-id": "4833ea1a-3371-4d3e-b28e-193fec18f723",
"date": "2019-03-07T11:01:36"
}
}
}
回答1:
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:
{
"subject": "Repeat-",
"isAllDay": true,
"isReminderOn": false,
"showAs": "free",
"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"
},
"recurrence": {
"pattern": {
"type": "weekly",
"interval": 1,
"daysOfWeek": ["Tuesday"]
},
"range": {
"type": "endDate",
"startDate": "2018-09-25",
"endDate": "2019-03-12"
}
}
}
回答2:
After I remove the 'recurrenceTimeZone' from the recurrence/range value, the server responses 200 OK and the new event is be created successfully.
It seems that the recurrenceTimeZone shouldn't be an invalid timezone value.
来源:https://stackoverflow.com/questions/55042532/cant-create-a-all-day-repeated-via-graph-api