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

%3CLINGO-SUB%20id%3D%22lingo-sub-1139421%22%20slang%3D%22en-US%22%3EGet%20the%20URL%20behind%20link%20items%20in%20SharePoint%20document%20library%20via%20REST%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1139421%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22votecell%20post-layout--left%22%3E%3CDIV%20class%3D%22js-voting-container%20grid%20fd-column%20ai-stretch%20gs4%20fc-black-200%22%3E%3CSPAN%3EI%20have%20a%20custom%20web%20part%20that%20I%20can%20connect%20to%20different%20data%20sources%20(e.g%20SharePoint%20Document%20Libraries).%20Then%20I%20can%20map%20the%20item%20properties%20from%20that%20document%20library%20to%20one%20of%20my%20different%20view%20templates.%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22postcell%20post-layout--right%22%3E%3CDIV%20class%3D%22post-text%22%3E%3CP%3EThe%20problem%20is%20when%20I%20add%20a%20Link%20item%20(external%20Url)%20in%20that%20document%20library%2C%20I%20cannot%20find%20an%20item%20property%20that%20stores%20the%20external%20Url.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F168035i04543162A165034F%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22clipboard_image_3.png%22%20title%3D%22clipboard_image_3.png%22%20%2F%3E%3C%2FSPAN%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3ERight%20now%20I%20get%20the%20item%20properties%20via%20SharePoint%20REST%20API.%20I%20checked%20the%20values%20of%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EFileRef%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EEncodedAbsUrl%3C%2FSTRONG%3E%2C%20but%20these%20are%20URLs%20pointing%20to%20the%20SharePoint%20document%20library%20file%2C%20and%20not%20to%20the%20external%20URL.%3C%2FP%3E%3CP%3EAfter%20some%20investigations%2C%20I've%20seen%20in%20the%20dev%20tools%20(F12)%20Network%20tab%2C%20there's%20a%20call%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CEM%3Ehttps%3A%2F%2F%7Bsiteurl%7D%2F_api%2FSP.Utilities.ShortcutLink.GetShortcutLink(%40a1)%3F%40a1%3D%7BsiteUrl%7D%2FShared%2520Documents%2F%3CA%20href%3D%22http%3A%2F%2Fwww.dummysite.com.url%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.dummysite.com.url%3C%2FA%3E%3C%2FEM%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ewhich%20will%20retrieve%20the%20actual%20linked%20external%20URL%2C%20but%20this%20not%20a%20good%20option%20for%20me%2C%20since%20making%20another%20REST%20call%20for%20each%20item%20will%20impact%20my%20performance.%3C%2FP%3E%3CP%3E%3CSTRONG%3ESo%20is%20there%20any%20item%20property%20that%20I%20could%20expand%20to%20get%20the%20external%20URL%2C%20via%20REST%20API%3F%3C%2FSTRONG%3E%3C%2FP%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1148630%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20the%20URL%20behind%20link%20items%20in%20SharePoint%20document%20library%20via%20REST%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1148630%22%20slang%3D%22en-US%22%3E%3CP%3EHi%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F538544%22%20target%3D%22_blank%22%3E%40VladSchiop%3C%2FA%3E%26nbsp%3B%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20use%20the%20renderListDataAsStream%20endpoint(%3CSPAN%3E_api%2Fweb%2Flists('%3CLISTID%3E')%2FRenderListDataAsStream%3C%2FLISTID%3E%3C%2FSPAN%3E)%20to%20get%20the%20item.%20If%20it's%20a%20link%2C%20you%20will%20be%20able%20to%20get%20it%20in%20the%20property%26nbsp%3B%3CSPAN%3E_ShortcutUrl.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3ERegards%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1206638%22%20slang%3D%22en-US%22%3ERe%3A%20Get%20the%20URL%20behind%20link%20items%20in%20SharePoint%20document%20library%20via%20REST%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1206638%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F538544%22%20target%3D%22_blank%22%3E%40VladSchiop%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%2F_api%2Fweb%2Flists%2FGetByTitle('%3CLIST%20name%3D%22%22%3E)%2Fitems%3F%24select%3D*%2CProperties%2Fvti_x005f_shortcuturl%26amp%3B%24expand%3DProperties%3C%2FLIST%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EShould%20do%20the%20trick.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Visitor
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.

 

clipboard_image_3.png
 
 

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?

2 Replies
Highlighted

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

Highlighted

@VladSchiop 

 

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

 

Should do the trick.