How to fetch files from a document library in one site collection to display in a web part in another site collection in SPO without Read permissions

Sachin 21 Reputation points
2021-07-12T11:02:57.31+00:00

I have a test project documents library in one site collection (projects) and I need to fetch and display these files in another site collection (HR) in SharePoint online , but the users from HR do not have permissions on test project documents and also we do not want to mirror the document library in HR site collection.

I was able to fetch the documents using API call :

var requestUri ="https://xxx.sharepoint.com/sites/<projects site>/_api/web/lists/getByTitle('Test Project Documents')/items?$select=EncodedAbsUrl,*,File/Name&$expand=File";

However regarding the read permissions for the library, I have an issue with it.

The test project documents contains information from different banks and we do not want to give permissions to everyone as they would have access to different bank documents as well.

The requirement was to display information in a web part in different pages for different banks without giving permissions to the project documents.

Please suggest how to proceed further regarding this.

Regards,
Sachin

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,683 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,972 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MichaelHan-MSFT 18,031 Reputation points
    2021-07-13T09:02:41.36+00:00

    Hi @Sachin

    Per my knowlegde, users need to have permissions to call the rest api to see the file.

    As a workaround, I would suggest you create a list to store the documents information, you could use rest api call to add the file information(name and url) to this list. Then display that list in pages.


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    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.


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.