Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
431 views
in Technique[技术] by (71.8m points)

azure active directory - Can't create an event with extended data

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. enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:

enter image description here

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:

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...