In SharePoint and OneDrive, is there any API that can get a list of files/folders shared with external users and expiry dates when external users' access will expire?

frob 4,261 Reputation points
2022-07-13T00:31:57.057+00:00

Hi there

In SharePoint and OneDrive, is there any API that can get a list of files/folders shared with external users and expiry dates when external users' access will expire?

Thank you.

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | OneDrive | For business | Windows
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 119.5K Reputation points MVP Volunteer Moderator
    2022-07-13T05:42:57.543+00:00

    There is, you can query the /permissions facet on each file/folder. Here's a sample script I wrote a while back: https://practical365.com/reporting-on-onedrive-for-business-shared-files/
    The above is using the Graph API, you can of course use CSOM or the PowerShell PnP module as alternative.
    There's also a built-in report you can generate via the UI: https://learn.microsoft.com/en-us/sharepoint/sharing-reports

    0 comments No comments

  2. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2022-07-13T07:00:56.35+00:00

    Hi @frob ,
    You can create a sharelink by following graph api

    POST /drives/{driveId}/items/{itemId}/createLink  
    POST /groups/{groupId}/drive/items/{itemId}/createLink  
    POST /me/drive/items/{itemId}/createLink  
    POST /sites/{siteId}/drive/items/{itemId}/createLink  
    POST /users/{userId}/drive/items/{itemId}/createLink  
    

    https://learn.microsoft.com/en-us/graph/api/driveitem-createlink?view=graph-rest-1.0&tabs=http

    You can also grant permissions by following url

    POST /shares/{encoded-sharing-url}/permission/grant  
    

    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.