对 Microsoft Graph API 执行 POST 请求以将成员添加到 AD 组

2024-01-07

我正在尝试通过 Azure 函数将成员添加到调用 Microsoft Graph API 的 AD 组

通过 Graph API 执行 GET 请求非常简单直接,但我找不到任何示例如何执行 Graph API 的 post 请求

我确实有一个 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/directoryObjects/{id}"
}

这是我成功用来检索图形响应的代码

public static async Task<HttpResponseMessage> GetDirectoryUsers(string graphToken, TraceWriter log, string displayName)
        {
            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", graphToken);

            string requestUrl = "https://graph.microsoft.com/v1.0/groups?$top=2&$filter=displayName eq '" + displayName + "'&$expand=Members";
            var request = new HttpRequestMessage(new HttpMethod("GET"), requestUrl);
            var response = await client.SendAsync(request);
            return response;
        }

但是,我完全不知道如何通过 Azure 函数中的 C# 代码执行请求,以将检索到的用户添加到另一个 AD。如何构造请求 URL?我应该如何处理该请求 URL 中的 odata id?

如果有人能以任何方式帮助我,我将不胜感激


一种添加子群/成员入群的复用方法(O365目前不支持添加子群入群)

/// <param name="graphClient"></param>
  /// <param name="groupId"></param>
  /// <param name="memberId">memberId/sub-group id</param>
  /// <returns></returns>
    public static async Task AddGroupMember1(GraphServiceClient 
    graphClient, string groupId, string memberId)
    { 
         User memberToAdd = new User { Id = memberId };
        //Group memberToAdd= new Group { Id = memberId };
        await graphClient.Groups[groupId].Members.References.Request().AddAsync(memberToAdd); 
   }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

对 Microsoft Graph API 执行 POST 请求以将成员添加到 AD 组 的相关文章

随机推荐