Forum Discussion

VladSchiop's avatar
VladSchiop
Copper Contributor
Jan 30, 2020

Get the URL behind link items in SharePoint document library via REST API

I have a custom web part that I can connect to different data sources (e.g SharePoint Document Libraries). Then I can map the item properties from that document library to one of my different view templates.

The problem is when I add a Link item (external Url) in that document library, I cannot find an item property that stores the external Url.

 

 
 

Right now I get the item properties via SharePoint REST API. I checked the values of FileRef and EncodedAbsUrl, but these are URLs pointing to the SharePoint document library file, and not to the external URL.

After some investigations, I've seen in the dev tools (F12) Network tab, there's a call to https://{siteurl}/_api/SP.Utilities.ShortcutLink.GetShortcutLink(@a1)?@a1={siteUrl}/Shared%20Documents/www.dummysite.com.url which will retrieve the actual linked external URL, but this not a good option for me, since making another REST call for each item will impact my performance.

So is there any item property that I could expand to get the external URL, via REST API?

  • BenLevitt96's avatar
    BenLevitt96
    Copper Contributor

    VladSchiop 

     

    /_api/web/lists/GetByTitle('<list name>)/items?$select=*,Properties/vti_x005f_shortcuturl&$expand=Properties

     

    Should do the trick.

     

  • Hi VladSchiop ,

     

    You can use the renderListDataAsStream endpoint(_api/web/lists('<listID>')/RenderListDataAsStream) to get the item. If it's a link, you will be able to get it in the property _ShortcutUrl.

     

    Regards

Resources