Home > Net >  How to Query new sites in SharePoint tenant by querying on site creation date with Microsoft Graph A
How to Query new sites in SharePoint tenant by querying on site creation date with Microsoft Graph A

Time:10-27

We want to query a SharePoint tenant periodically for any new sites/subsites created since the last time the query was run (e.g. once every 5 minutes).

We are open to running graph queries at the SharePoint tenant level or the SharePoint site collection level.

This tenant has >50,000 sites subsites in it. Enumerating them all takes too long. So we are hoping to create a graph query that can identify only sites with a creation date within a narrow range so we can make this process faster.

Cany anyone share more information on how to achieve such a query across the tenant, or site collection, for site creation date? Thanks in advance.

CodePudding user response:

The fastest way to list all tenant's sites (large amount) is querying a hidden system list. It requires to have the right permissions to read listitems.

First, list all SP lists via the query: https://graph.microsoft.com/v1.0/sites/<yourtenant>-admin.sharepoint.com/Lists/?select=id,name

Next, via MS graph, you can query and filter the listitems in the list with the displayname DO_NOT_DELETE_SPLIST_TENANTADMIN_ALL_SITES_AGGREGATED_SITECOLLECTIONS as all sites' references are there. You can use the integrated pagination URL in @odata.nextLink property. Read : https://learn.microsoft.com/en-us/graph/paging

Also, another option, via a search query it is possible too : https://graph.microsoft.com/v1.0/sites?search='<site_name_or_alias>'&filter=createdDateTime ge '2020-10-26T00:00:00Z'. However, beware of the fact that just a few properties are supported for filtering if you use the search.

  • Related