How to add members to a Group using Microsoft Graph API

10,009

Solution 1

That is correct. What you're technically passing is an ODATA Reference (ref$) to the user object within Active Directory rather than just an id.

To illustrate, lets take this fictitious user:

{
    "@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": "[email protected]",
    "mobilePhone": null,
    "officeLocation": "12/1110",
    "preferredLanguage": "en-US",
    "surname": "Bowen",
    "userPrincipalName": "[email protected]"
}

If we wanted to add Megan to the a Group with an id of 02bd9fd6-8f93-4758-87c3-1fb73740a315 the call would look like this:

POST https://graph.microsoft.com/v1.0/groups/02bd9fd6-8f93-4758-87c3-1fb73740a315/members/$ref
Content-type: application/json

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

Solution 2

It is also working when passing user 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 - group object id

user_id - user object id

Share:
10,009
briandenny
Author by

briandenny

Updated on June 08, 2022

Comments

  • briandenny
    briandenny almost 2 years

    How do I add Members to a Group via Microsoft Graph API?

    According to documentation for adding Member to a particular Group, it requires the call below:

    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}"
    }
    

    My questions lies in this API:

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

    • members => adding members to the group

    Now where is the users/members data/parameter to be added or posted?

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

    Do I post @odata.id values as a member/users parameter when adding a member to a group?