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?