List folder contents of 'Shared with Me' folder from Office 365 OneDrive (Sharepoint) for Business and Education using the REST api?

时光总嘲笑我的痴心妄想 提交于 2019-12-01 00:34:23

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!