Graph API - Get list of SharePoint sites with Sites.Selected

Manuel Suarez 0 Reputation points
2024-10-01T15:51:55.1166667+00:00

Hello:

I am trying to integrate with Sharepoint via the Microsoft Graph API. I have already set up an Azure app with Sites.Selected permissions and configured the app to have read access to a specific list of sites. For context, I am using raw HTTP calls to the MS graph v.1.0 API to build the integration.

The problem is that I can access the files/folders of a site provided that the user manually inputs the ID of said site, but there is no way to list all the sites that my application has access to.

I have already tried the solution proposed in this thread:

https://learn.microsoft.com/en-us/answers/questions/1331590/graph-api-get-list-of-sharepoint-sites-with-sites

But it does not work as of october 2024, doing a call to the /sites/ endpoint returns an empty list:

# setup auth session
auth_headers = {
    "Authorization": f"Bearer {access_token}",
}

session = requests.Session()
session.headers.update(auth_headers)


# list all sites
sharepoint_site_list_endpoint = "https://graph.microsoft.com/v1.0/sites"

response = session.get(sharepoint_site_list_endpoint)

sites_list = response.json()["value"]

print(f"Got {len(sites_list)} sites") # this always returns 0

Even if the permissions expansion is added to the query params.

# setup auth session
auth_headers = {
    "Authorization": f"Bearer {access_token}",
}

session = requests.Session()
session.headers.update(auth_headers)


# list all sites
sharepoint_site_list_endpoint = 


response = session.get(sharepoint_site_list_endpoint)

sites_list = response.json()["value"]

print(f"Got {len(sites_list)} sites") # this prints returns 0

It seems like there is no way to get a list of sites that the application has access to in order to display them to the end user, which is not ideal, since getting the site ID of a sharepoint site is not an easy process.

Given the above, my questions are:

  • Are there other ways of finding out which sites my app has access to?
  • Is it possible to setup another permission to be able to list Sharepoint sites without having access to its contents?
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,044 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,980 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 106.2K Reputation points MVP
    2024-10-01T16:57:31.79+00:00

    There's no way for an application with Sites.Selected permissions to get this info. The code above will only work if you have the necessary permissions (Sites.Read.All at minimum), which your app does not. Moreover, if your app is running in the context of a user (delegate permissions), the /sites query will not work altogether - it's only supported for application permissions.


  2. Yanli Jiang - MSFT 26,091 Reputation points Microsoft Vendor
    2024-10-09T09:38:27.6466667+00:00

    Hi @Manuel Suarez ,

    If you want to get all the files accessible under this app, unfortunately, there is no such API yet.

    Good day!


    If the answer is helpful, please click "Accept as 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.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.