skip to Main Content

I have trouble with the graph api /sites?search= call.

In fact, my request returns only 11 sites out of 16. I don’t see the difference between these sites that could explain this.
I connect with the credentials of an application (client secret) on the api and I have the Sites.ReadWriteAll (Application) permission.

Maybe the application doesn’t have access to certain sites and needs to be explicitly granted somewhere on Azure? Any help is welcome.

2

Answers


  1. I registered one Azure AD application and granted Sites.ReadWrite.All permission of Application type:

    enter image description here

    Now, I generated access token using client credentials flow via Postman with below parameters:

    POST https://login.microsoftonline.com/tenantID/oauth2/v2.0/token
    grant_type:client_credentials
    client_id: appID
    client_secret: secret 
    scope: https://graph.microsoft.com/.default
    

    Response:

    enter image description here

    When I used the above token to call graph API with search query, I got only 16 sites out of 21:

    GET https://graph.microsoft.com/v1.0/sites?search=*
    

    Response:

    enter image description here

    As @user2250152 suggested, you can make use of GetAllSites endpoint to list all sites across geographies in an organization.

    GET https://graph.microsoft.com/v1.0/sites/getAllSites?$count=true
    

    Response:

    enter image description here

    I got the same results when I used below graph call as all sites are in same geographic location:

    GET https://graph.microsoft.com/v1.0/sites?$count=true
    

    Response:

    enter image description here

    When I checked the difference between these sites, I observed /sites?search= call won’t return sites that are created for user’s personal OneDrive accounts that looks like:

    https://xxxxxxxxxx-my.sharepoint.com/personal/user_xxxxxxxxx_onmicrosoft_com 
    

    This /sites?search= call also won’t return below search site:

    https://xxxxxxxxxxxx.sharepoint.com/search
    

    But GetAllSites and ListAllSites endpoint returns all these sites in response.

    Reference:

    Try to retrieve all sites, but in some cases, some sites are not found in the search – Microsoft Q&A by RajeshKumar-MSFT

    Login or Signup to reply.
  2. Try to add Sites.Read.All, Sites.ReadWrite.All & Sites. Selected Permissions. If you don’t have the permission to the site, you will be unable to search the site

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search