在 Microsoft Graph API 中创建具有所有者的组所有者、Microsoft、Graph、API

2023-09-07 09:09:32 作者:一脸废样

I have a Office 365 Group that I would like to add through the Microsoft Graph API. Based on the API documentation, I believe I need

POST https://graph.microsoft.com/v1.0/groups
Content-type: application/json
Content-length: 244

{
  "description": "Self help community for library",
  "displayName": "Library Assist",
  "groupTypes": [
    "Unified"
  ],
  "mailEnabled": true,
  "mailNickname": "library",
  "securityEnabled": false
}
Microsoft Graph 桌面应用程序

But when I try to add

"owner": [{ "@odata.id": "https://graph.microsoft.com/v1.0/users/{id}"}]

I get an error (The id is really an id that exists in the office so I don't want to put it here).

They work if I first run the create group and then the add owner but not together. Why?

Would like to make it as easy for me as possible. I'm putting postman in the tags just because that's the tools I'm currently using

解决方案

Actually this is supported and possible today using OData bind syntax (i.e. your syntax is incorrect). NOTE: This is our bad, not your, because we haven't documented this supported behavior. I'll file a bug on our side to document this.

In the meantime, try adding this to your request (it worked for me), and let us know if this works for you:

"owners@odata.bind": ["https://graph.microsoft.com/v1.0/users/{id}"]

In fact, in the same request you can also bind members as part of the request:

"owners@odata.bind": [ "https://graph.microsoft.com/v1.0/users/{id1}" ], "members@odata.bind": [ "https://graph.microsoft.com/v1.0/users/{id1}", "https://graph.microsoft.com/v1.0/users/{id2}" ]

Not sure what the limits are on the number of items you can put in the binding collection, but I'm sure there is one. I'll see if one of the devs can comment on this.

Hope this helps,