2
votes

Is there a way to get the contents of the 'Shared with Me' folder from the Office 365 (Sharepoint) REST api ?

I can't see anything in the api reference reagrding this. https://msdn.microsoft.com/office/office365/APi/files-rest-operations

1

1 Answers

2
votes

Found the solution to this...

Instead of using the files api you must use the sharepoint search api. The following endpoint with the KQL query parameters can be used to get a list of files 'shared with me'

https://{tenant}-my.sharepoint.com/_api/search/query?querytext='(SharedWithUsersOWSUSER:{UserAccountName} AND contentclass:STS_ListItem_MySiteDocumentLibrary)'

This above will get a list of files 'shared with me' but not anything inside a shared folder. To get the items inside a shared folder you can use the following endpoint.

https://{tenant}-my.sharepoint.com/_api/search/query?querytext='(ParentLink:{ParentLink})'

Make sure the parent link is url encoded. You can retrieve the parent link from the folder properties.

Finally to get the account name used in the first request you can make a request to the sharepoint webs api.

https://{tenant}-my.sharepoint.com/_api/web/CurrentUser