title: Executing POST request for Microsoft Graph API to add members to an AD group
body: <p>I am trying to add members to an AD groups invoking Microsoft Graph API through an Azure Function</p>
  
  <p>It is very easy and straightforward to execute GET requests through Graph API's, but I can't find any examples how I could execute post requests for the Graph API</p>
  
  <p>I do have an example of a post request for the Graph API which is</p>
  
  <pre><code>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}"
  }
  </code></pre>
  
  <p>Here is the code I successfully use to retrieve the Graph response</p>
  
  <pre><code>public static async Task&lt;HttpResponseMessage&gt; 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&amp;$filter=displayName eq '" + displayName + "'&amp;$expand=Members";
              var request = new HttpRequestMessage(new HttpMethod("GET"), requestUrl);
              var response = await client.SendAsync(request);
              return response;
          }
  </code></pre>
  
  <p>However, I am completely lost how I could execute the request through a C# code within the Azure function to ADD the retrieved users to another AD. How can construct the request URL? How should I handle the odata id within that request URL?</p>
  
  <p>If anyone could help me in any way, I would greatly appreciate it</p>