问题
I am trying to create a calendar event with extended data using Microsoft Graph API.(actually, I am trying to converting the existing open extension to schema extension since I couldn't filter the non-id extended value of the open extension.)
Before my try, I have already created my schema extension successfully and creating a calendar event with the schema extension responses an error code "BadRequest" and message "Requests must contain extension changes exclusively".
I tried to do this by following the doc.
POST https://graph.microsoft.com/v1.0/me/calendars/{calendar-group-id}/events
{
"subject": "schema extension test",
"body": {
"contentType": "HTML",
"content": "schema extension test"
},
"start": {
"dateTime": "2021-01-22T12:00:00",
"timeZone": "Eastern Standard Time"
},
"end": {
"dateTime": "2021-01-23T14:00:00",
"timeZone": "Eastern Standard Time"
},
"attendees": [],
"extendedData": {
"courseId": "11",
"materialId": "22",
"courseType": "video"
}
}
response:
{
"error": {
"code": "BadRequest",
"message": "Requests must contain extension changes exclusively.",
"innerError": {
...
}
}
}
Without extendedData
, creating the event responses success, and after creating the event, if I patch
the event with only extendedData
, it responses an error "A type named 'Microsoft.OutlookServices.OpenTypeExtension' could not be resolved by the model. When a model is available, each type name must resolve to a valid type".
PATCH https://graph.microsoft.com/v1.0/me/calendars/{calendar-group-id}/events/{event-id}
{
"extendedData": {
"courseId": "11",
"materialId": "22",
"courseType": "video"
}
}
response:
{
"error": {
"code": "RequestBodyRead",
"message": "A type named 'Microsoft.OutlookServices.OpenTypeExtension' could not be resolved by the model. When a model is available, each type name must resolve to a valid type.",
"innerError": {
...
}
}
}
I was able to succeed when I used Graph API explorer with signed in user by consent Calendars.Read
permission.
But if I try the same thing in postman, it doesn't work.
I already have granted all calendar permissions including delegated and application permissions in Azure.
回答1:
This is because your schema extension name is not extendedData
.
When you use POST https://graph.microsoft.com/v1.0/schemaExtensions
to create an extension for Event type, the real name will be prefixed.
Like this:
And based on this known issue of Microsoft Graph:
You cannot specify a schema extension in the same operation as creating an instance of contact, event, message, or post. You must first create the resource instance and then do a PATCH to that instance to add a schema extension and custom data.
So we need to create the event first and then update it.
When updating the event, we need to specify the real extension name:
来源:https://stackoverflow.com/questions/65614549/cant-create-an-event-with-extended-data