如何使用Microsoft Graph API将成员添加到组

时间:2017-12-05 12:21:01

标签: azure-active-directory microsoft-graph

如何通过Microsoft Graph API将成员添加到组?

根据将成员添加到特定群组的文档,需要进行以下调用:

POST https://graph.microsoft.com/v1.0/groups/{id}/members/$ref
Content-type: application/json
Content-length: 30
{
    "@odata.id": "https://graph.microsoft.com/v1.0/users/{id}"
}

我的问题在于这个API:

https://graph.microsoft.com/v1.0/groups/{id}/members/$ref
  • {id} =>小组ID,

  • members =>将成员添加到组

现在添加或发布的用户/成员数据/参数在哪里?

"@odata.id": "https://graph.microsoft.com/v1.0/users/{id}"吗?

将成员添加到群组时,是否将@odata.id值作为成员/用户参数发布?

2 个答案:

答案 0 :(得分:4)

这是正确的。您在技术上传递的是ODATA参考(CREATE OR REPLACE FUNCTION insert_authid_fn() RETURNS trigger AS $$ BEGIN execute format ('GRANT ALL ON DATABASE testdb TO %I',NEW.username); RETURN NEW; END; $$ LANGUAGE plpgsql; )到Active Directory中的ref$对象,而不仅仅是user

为了说明,让我们来看看这个虚构的id

user

如果我们想将Megan添加到{ "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity", "id": "48d31887-5fad-4d73-a9f5-3c356e68a038", "businessPhones": [ "+1 412 555 0109" ], "displayName": "Megan Bowen", "givenName": "Megan", "jobTitle": "Auditor", "mail": "MeganB@M365x214355.onmicrosoft.com", "mobilePhone": null, "officeLocation": "12/1110", "preferredLanguage": "en-US", "surname": "Bowen", "userPrincipalName": "MeganB@M365x214355.onmicrosoft.com" } id的群组,则呼叫将如下所示:

02bd9fd6-8f93-4758-87c3-1fb73740a315

答案 1 :(得分:0)

在传递用户ID时也可以使用:

POST url: https://graph.microsoft.com/v1.0/groups/{group_id}/members/$ref
Content-type: application/json

Content string: {"@odata.id": "https://graph.microsoft.com/v1.0/users/{user_id}"}

group_id-组对象ID

user_id-用户对象ID