Getting a List of Files from a Sharepoint Shared Link

Written by James McDonald

January 27, 2022

So recently I had a customer ask if they can be notified when the files change in a Microsoft Teams Sharepoint URL which was shared with Contribute permissions with sign-in NOT required.

The link provided did not allow the person to choose “Sync” and then mirror the folder structure in their Own OneDrive
And there doesn’t appear to be a way to set up alerts because you can’t alert “anonymous”.


An example of the link provided is the following:
https://example.sharepoint.com/:f:/s/mytestteamsite/EhWIF7ehmopLosy9HzbJotQBom1_rk9goDptDd-VOVHcxg

When you click on a sharepoint Shared Link URL similar to the above ( While not authenticated ) it will redirect you to the “proper” URL similar to the following and allow you to access the files.

https://example.sharepoint.com/sites/mytestteamsite/Shared%20Documents/Forms/AllItems.aspx?id=%2Fsites%2Fmytestteamsite%2FShared%20Documents%2FTestSharedFolder&p=true

Once you have the above URL you can get the list of files in XML format by editing the URL to include this snippet _api/web/lists/getbytitle(‘Documents’)/items?

https://example.sharepoint.com/sites/mytestteamsite/_api/web/lists/getbytitle(‘Documents’)/items?$select=FileLeafRef,FileRef&id=%2Fsites%2Fmytestteamsite%2FShared%20Documents%2FTestSharedFolder&p=true

Requesting the above URL will return an XML list of filename (FileLeafRef) and filepath (FileRef) which you can then compare programmatically with previous output and alert people via email when a change happens.



0 Comments

Submit a Comment

Your email address will not be published.

You May Also Like…

List your VSCode Extensions

Ever wondered what extensions you have installed and want to keep a list? This actually is a good way to audit your...

array_merge vs the + operator

<?php $options = [ 'rootNode' => 'response' ]; // array_merge // the same key appearing later will overwrite echo...