我有一个Office 365组,我想通过Microsoft Graph API添加.基于API文档,我相信我需要
POST https://graph.microsoft.com/v1.0/groups
Content-type: application/json
Content-length: 244
Run Code Online (Sandbox Code Playgroud)
{
"description": "Self help community for library",
"displayName": "Library Assist",
"groupTypes": [
"Unified"
],
"mailEnabled": true,
"mailNickname": "library",
"securityEnabled": false
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试添加时
"owner": [{ "@odata.id": "https://graph.microsoft.com/v1.0/users/{id}"}]
Run Code Online (Sandbox Code Playgroud)
我收到一个错误(该ID实际上是办公室中存在的ID,所以我不想把它放在这里).
如果我首先运行创建组然后添加所有者但不在一起,它们可以工作.为什么?
想尽可能让我这么容易.我将邮递员放在标签中只是因为那是我目前正在使用的工具
实际上,今天使用OData绑定语法(即您的语法不正确)支持并且可能.注意:这是我们的坏,而不是你的,因为我们没有记录这种支持的行为.我会在我们这边提交一个错误来记录这个.
在此期间,请尝试将此添加到您的请求中(它对我有用),并告诉我们这是否适合您:
"owners@odata.bind": ["https://graph.microsoft.com/v1.0/users/{id}"]
实际上,在同一个请求中,您还可以将成员绑定为请求的一部分:
"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}"
]
不确定你可以在绑定集合中放置的项目数量有什么限制,但我确信有一个.我会看看其中一个开发者是否可以对此发表评论.
希望这可以帮助,
丹,谢谢你的解决方案!基于它,我创建了也适用于 Graph API 的解决方案。诀窍是使用以下从 Graph 客户端库继承 Group 的类:
public class GroupExtended : Group
{
[JsonProperty("owners@odata.bind", NullValueHandling = NullValueHandling.Ignore)]
public string[] OwnersODataBind { get; set; }
[JsonProperty("members@odata.bind", NullValueHandling = NullValueHandling.Ignore)]
public string[] MembersODataBind { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
然后像这样添加它:
var newGroup = new GroupExtended
{
DisplayName = displayName,
Description = description,
MailNickname = mailNickname,
MailEnabled = true,
SecurityEnabled = false,
Visibility = isPrivate == true ? "Private" : "Public",
GroupTypes = new List<string> { "Unified" }
};
if (owners != null && owners.Length > 0)
{
var users = GetUsers(graphClient, owners);
if (users != null)
{
newGroup.OwnersODataBind = users.Select(u => string.Format("https://graph.microsoft.com/v1.0/users/{0}", u.Id)).ToArray();
}
}
if (members != null && members.Length > 0)
{
var users = GetUsers(graphClient, members);
if (users != null)
{
newGroup.MembersODataBind = users.Select(u => string.Format("https://graph.microsoft.com/v1.0/users/{0}", u.Id)).ToArray();
}
}
await graphClient.Groups.Request().AddAsync(newGroup);
Run Code Online (Sandbox Code Playgroud)
此处描述了整个解决方案:http : //sadomovalex.blogspot.com/2018/11/create-azure-ad-groups-with-initial.html。
| 归档时间: |
|
| 查看次数: |
1876 次 |
| 最近记录: |