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,206 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.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,131 questions
OneDrive Management
OneDrive Management
OneDrive: A Microsoft file hosting and synchronization service.Management: The act or process of organizing, handling, directing or controlling something.
1,072 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Vasil Michev 90,396 Reputation points MVP
    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 29,031 Reputation points Microsoft Vendor
    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.