How to access all SharePoint documents for all the sites in the tenancy?

GR 41 Reputation points
2022-08-18T13:08:42.767+00:00

Hi,

We're creating token for a specific client's tenancy, and we want to be able to access all SharePoint documents for all the sites in the tenancy. Is there a way to access those using a generic SharePoint API and one access token?

There are two files store:

  • one in a personal OneDrivce folder in the tenancy
  • one in a SharePoint site folder, e.g. for a Yammer group

The url to the file in a personal OneDrivce folder starts with '<tenant-name>-my.', whereas the SharePoint site document url doesn't contain the '-my' suffix:

  • file in a personal OneDrivce folder: https://<tenant-name>-my.sharepoint.com/personal/example-customer-com/_layouts/15/Doc.aspx?sourcedoc=%7B1115F5DE-213E-465D-B9A3-893860C2CA11%7D&file=Document1.docx&action=default&mobileredirect=true&DefaultItemOpen=1
  • SharePoint site document: https://<tenant-name>.sharepoint.com/sites/<site-id/group>/_layouts/15/Doc.aspx?sourcedoc=%7B222EF3FA-25F4-4A0E-8A52-5B087985C44D%7D&file=Document2.docx&action=default&mobileredirect=true
  1. We have been trying to create an access token with a https://microsoft.sharepoint-df.com/AllSites.Read scope, but it ends with incorrect audience issue. We hoped that since those are SharePoint documents in the same tenancy, we would be able to access them.
  2. We have used two different access tokens with different scopes. We explicitly added https://<tenant-name>-my.sharepoint.com/... to the first scope, and the https://<tenant-name>.sharepoint.com to the second scope, to be able to download those files using GetFileById. This works, however we would prefer to use a single generic scope without providing every url and needed a separate tokens.

Additionally, we have tried using the Microsoft Graph API, but it seems we don't have enough details to use it, e.g. we don't know the drive and item ids and the file path.

Is there a way to access all SharePoint documents within a tenancy using a generic API with details from file's urls? The details we have are: <tenant-name>, <site-id>, sourcedoc, file name?

Thanks

Microsoft Graph Files API
Microsoft Graph Files API
A Microsoft API to create an app that connects with files across OneDrive, OneDrive for Business, and SharePoint document libraries.
320 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.
1,801 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tong Zhang_MSFT 8,881 Reputation points
    2022-08-19T07:06:38.593+00:00

    Hi @GR ,

    According to my research and testing, you can use the following graph API to access SharePoint documents for the sites in the tenant .Note: You need to have Sites.Read.All permission to these sites.

    https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-title}/items  
    

    Hope it can help you. Thanks for your understanding.


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