Need Rest API to get user's all groups(direct group and indirect group)

Pankaj Kumar 26 Reputation points

We are looking for REST API to get user's all direct and indirect group.

Ex: REST API is only returning groups for which user is directly listed as a member. If user is a member of a site group(Marketing group), indirectly through membership in a nested active directory group then REST API does not return top level group (in this case Marketing group).

Rest API is providing only direct group, we are looking for REST API to get all direct and indirect group for a user.

A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,027 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Pankaj Kumar 26 Reputation points

    Hi @Tong Zhang_MSFT ,

    No, This is not resolving our issue, we are not getting AD groups. It is only providing SP groups

    1 person found this answer helpful.

  2. Tong Zhang_MSFT 9,136 Reputation points

    Hi @Pankaj Kumar ,
    According to my research and testing, please try to use the following code to get all groups:

    function GetAllSiteGroups() {  
                // _spPageContextInfo.webAbsoluteUrl - will give absolute URL of the site where you are running the code.  
                // You can replace this with other site URL where you want to apply the function  
                url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups",  
                type: "GET",  
                       // Accept header: Specifies the format for response data from the server.  
                       "Accept": "application/json;odata=verbose"  
                success: function (data, status, xhr) {  
                    var dataresults = data.d.results;  
                    for (var i = 0; i < dataresults.length; i++) {  
                    console.log("Group Title - " + dataresults[i]["Title"]);  
                error: function (xhr, status, error) {  

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.