Friday, January 6, 2017

Retrieving search results from private Groups in Office 365 via REST

By default when you run a search REST query against SharePoint Online results from private Office 365 Groups are not included.

By adding &Properties=’EnableDynamicGroups:true’ to the URL, you will also get results from private groups.

If you are running REST POST requests, add the following to your JSON payload (odata=verbose):

'Properties':{  
         'results':[  
            {  
               'Name':'EnableDynamicGroups',
               'Value':{  
                  'BoolVal':true,
                  'QueryPropertyValueTypeIndex':3
               }
            }
         ]
      }

When using CSOM, it seems dynamic groups are included by default.

7 comments:

  1. Thanks for this post. It helped us. However we are seeing only few private groups are listed. Any suggestion how to list all private groups along with public.

    ReplyDelete
    Replies
    1. Could it be groups where no one has ever accessed the SharePoint site?

      Delete
    2. It might be better to use the Graph API to list all groups.

      Delete
  2. This works with pnp-js-core:
    public componentWillMount(): void {
    let sq: SearchQuery = {
    Querytext: "SPContentType=SiteDirectoryItem",
    RowLimit: 500,
    Properties:[
    {Name:"EnableDynamicGroups",Value:{BoolVal:true,QueryPropertyValueTypeIndex:QueryPropertyValueType.BooleanType}}
    ]
    };
    pnp.sp.search(sq).then((resuls: SearchResults) => {
    debugger;
    });
    }

    ReplyDelete
  3. Thanks Mikael, for CSOM, we need to add this property also to search Private Groups:

    var qrv = new QueryPropertyValue();
    qrv.BoolVal = true;
    qrv.QueryPropertyValueTypeIndex = 3;
    keywordQuery.Properties.SetQueryPropertyValue("EnableDynamicGroups", qrv);

    ReplyDelete