How can I get all files a specific user has access to using sharepoint search api

Gal Yaniv 65 Reputation points
2023-03-12T17:31:21.04+00:00

I need to get all the files a spesific user has view permissions to in a site collection.

I thought of using the sharepoint search api for that task. The sharepoint search api has the following filter: "contentclass:sts_listitem_documentlibrary" to get all the files the logged in user has access to.

I know that the sharepoint rest api has the "getusereffectivepermissions" filter to get files permissions for different users, but I need to perform this task with one api call (or a very small amount of api calls).

so my question is how can I combine contentclass:sts_listitem_documentlibrary and getusereffectivepermissions to get all the files a specific user has view permissions to with a very small amount of api calls assuming that I have a lot of files in my site.

Microsoft 365 and Office | SharePoint | Development
Microsoft 365 and Office | SharePoint | For business | Windows
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2023-03-13T07:35:03.81+00:00

    Hi @Gal Yaniv

    You will need to loop all the files and check if the user have permission to the item by the following endpoint

    /_api/web/lists(listid)/items(itemid)/getUserEffectivePermissions(userName)
    
    

    This will make huge amount of api calls. As a workaround, I will recommend you to use powershell to get the user permission report. You can refer to the following article to get the csv report

    https://www.sharepointdiary.com/2018/09/sharepoint-online-get-user-permission-report-using-powershell.html


    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.


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.