Sharepoint Rest: Get library url

%3CLINGO-SUB%20id%3D%22lingo-sub-191873%22%20slang%3D%22en-US%22%3ESharepoint%20Rest%3A%20Get%20library%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-191873%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EHow%20do%20I%20get%20the%20library%20URL%3F%26nbsp%3B%3C%2FP%3E%3CP%3EI%20tried%20with%20ServerRestUrl%20but%20I%20am%20getting%20undefined%20%3A%5C%3C%2Fimg%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%20regards%3C%2FP%3E%3CP%3EAmerico%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-191873%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAPIs%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-192651%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20Rest%3A%20Get%20library%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-192651%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20are%20using%20SharePoint%20Online%2C%20you%20can%20try%20the%20below%20code%20for%20retrieving%20the%20Library%20URL%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3E%24.ajax(%7B%0A%20%20%20%20%20%20%20%20url%3A%20hostweburl%20%2B%20%22%2F_api%2Fweb%2FAppTiles%3F%24filter%3DBaseTemplate%20eq%20101%22%2C%0A%20%20%20%20%20%20%20%20method%3A%20%22GET%22%2C%0A%20%20%20%20%20%20%20%20headers%3A%20%7B%20%22Accept%22%3A%20%22application%2Fjson%3B%20odata%3Dverbose%22%20%7D%2C%0A%20%20%20%20%20%20%20%20success%3A%20function%20(response)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20var%20libItems%20%3D%20%22%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%24(response.d.results).each(function()%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20libItems%20%2B%3D%22%3CLI%3E%3CA%20href%3D%22%26quot%3B%2Bthis.Target%2B%26quot%3B%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E%22%2Bthis.Title%2B%22%3C%2FA%3E%3C%2FLI%3E%22%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20%24('%23libitems').html(libItems)%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20console.log(response)%3B%0A%20%20%20%20%20%20%20%20alert(response.d.results.length)%3B%0A%20%20%20%20%20%20%20%20%7D%2C%0A%20%20%20%20%20%20%20%20error%3A%20function%20(data)%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20failure(data)%3B%0A%20%20%20%20%20%20%20%20%7D%0A%7D)%3B%3CBR%20%2F%3E%0A%3C%2FPRE%3E%3CP%3ESharePoint%20Online%20returns%20the%20collection%20of%20lists%2C%20libraries%20and%20subsites%20under%20the%20below%20rest%20endpoint%2C%3C%2FP%3E%3CP%3E%3CEM%3Ehttps%3A%2F%2F%3CTENANT%3E.sharepoint.com%2F_api%2Fweb%2FAppTiles%3C%2FTENANT%3E%3C%2FEM%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3BRegards%2C%3C%2FP%3E%3CP%3EShantha%20Kumar%20T%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-192633%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20Rest%3A%20Get%20library%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-192633%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EThanks!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThere%20is%20a%20little%20difference%20with%20the%20proposal%20you%20posted.%20I%20need%20to%20get%20the%20list%20of%20all%20libraries%20that%20is%20why%20I%20am%20using%3A%26nbsp%3B%3C%2FP%3E%3CPRE%3Eurl%3A%20appweburl%20%2B%20%22%2F_api%2FSP.AppContextSite(%40target)%2Fweb%2Flists%3F%40target%3D'%22%20%2B%20hostweburl%20%2B%20%22'%22%3C%2FPRE%3E%3CP%3Ewithout%20pointing%20to%20a%20specific%20library.%3C%2FP%3E%3CP%3EThe%20result%20I%20am%20getting%20doesn't%20contains%20%22EncodedAbsUrl%22%20in%20the%20respons.%3C%2FP%3E%3CP%3EThis%20is%20the%20response%20for%20one%20of%20the%20libraries%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20399px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F33937i14564508E1E3C061%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20alt%3D%22Sk%C3%A4rmklipp.PNG%22%20title%3D%22Sk%C3%A4rmklipp.PNG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBest%20regards%3C%2FP%3E%3CP%3EAmerico%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-192071%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20Rest%3A%20Get%20library%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-192071%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22crayon-syntax%20crayon-theme-github%20crayon-font-consolas%20crayon-os-pc%20print-yes%20notranslate%22%3E%3CDIV%20class%3D%22crayon-main%22%3E%3CP%3ECan%20you%20try%20below%3F%3C%2FP%3E%3CTABLE%3E%3CTBODY%3E%3CTR%3E%3CTD%3E%3CDIV%20class%3D%22crayon-pre%22%3E%3CDIV%20class%3D%22crayon-line%22%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3E_api%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3Eweb%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3Elists%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-e%22%3Egetbytitle%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-s%22%3E'Document%20Library%20Name'%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E)%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3EItems%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E%3F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E%24%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3Eselect%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-o%22%3E%3D%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3ETitle%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3EFileLeafRef%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3EEncodedAbsThumbnailUrl%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E%2C%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3EEncodedAbsUrl%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3EThe%20example%20above%20returns%20information%20about%20your%20file%20such%20as%20the%20name%2C%20full%20url%20and%20the%20internal%20%E2%80%9CTitle%E2%80%9D%3A%3C%2FP%3E%3CP%3E%3CIMG%20src%3D%22http%3A%2F%2Fmichaelsoriano.com%2Fwp-content%2Fuploads%2F2015%2F12%2Frest-select2.gif%22%20border%3D%220%22%20alt%3D%22rest-select2%22%20width%3D%22531%22%20height%3D%22160%22%20%2F%3E%3C%2FP%3E%3CP%3EFor%20instances%20where%20you%20want%20to%20know%20the%20%E2%80%9Ctype%E2%80%9D%20of%20document%20library%20it%20is%20(example%20Picture%20Library%20vs%20Document%20Library)%2C%20use%3A%3C%2FP%3E%3CDIV%20class%3D%22crayon-syntax%20crayon-theme-github%20crayon-font-consolas%20crayon-os-pc%20print-yes%20notranslate%22%3E%3CDIV%20class%3D%22crayon-plain-wrap%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22crayon-main%22%3E%3CTABLE%3E%3CTBODY%3E%3CTR%3E%3CTD%3E%3CDIV%20class%3D%22crayon-nums-content%22%3E%3CDIV%20class%3D%22crayon-num%22%3E1%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FTD%3E%3CTD%3E%3CDIV%20class%3D%22crayon-pre%22%3E%3CDIV%20class%3D%22crayon-line%22%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3E_api%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3Eweb%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3Elists%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-e%22%3Egetbytitle%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-s%22%3E'Document%20Library%20Name'%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E)%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3EBaseTemplate%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3EAlthough%20some%20information%20regarding%20document%20libraries%20require%20an%20entirely%20new%20endpoint.%20This%20includes%20file%20paths%2C%20subfolders%2C%20thumbnails%20and%20such.%3C%2FP%3E%3CDIV%20class%3D%22crayon-syntax%20crayon-theme-github%20crayon-font-consolas%20crayon-os-pc%20print-yes%20notranslate%22%3E%3CDIV%20class%3D%22crayon-plain-wrap%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22crayon-main%22%3E%3CTABLE%3E%3CTBODY%3E%3CTR%3E%3CTD%3E%3CDIV%20class%3D%22crayon-nums-content%22%3E%3CDIV%20class%3D%22crayon-num%22%3E1%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FTD%3E%3CTD%3E%3CDIV%20class%3D%22crayon-pre%22%3E%3CDIV%20class%3D%22crayon-line%22%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3E_api%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3Eweb%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-e%22%3EGetFolderByServerRelativeUrl%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E(%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-s%22%3E'%22Folder%20Name%22'%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-sy%22%3E)%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-o%22%3E%2F%3C%2FSPAN%3E%3CSPAN%20class%3D%22crayon-v%22%3EFiles%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3EThe%20above%20contains%20an%20entire%20new%20set%20of%20information%20regarding%20your%20library.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-191879%22%20slang%3D%22en-US%22%3ERe%3A%20Sharepoint%20Rest%3A%20Get%20library%20url%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-191879%22%20slang%3D%22en-US%22%3E%3CP%3EI%20managed%20solve%20the%20url%20thing%20by%20creating%20it%20manually%20like%20this%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ehostweburl%20%2B%20'%2F'%20%2B%20this.Title%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EBut%20I%20noted%20another%20problem%3A%3C%2FP%3E%3CP%3EIn%20the%20site%20I%20have%20created%202%20libraries%20%22test%22%20and%20%22test2%22%20but%20in%20the%20result%2C%20besides%20this%202%20libraries%2C%20I%20am%20also%20getting%20system%20libraries%20like%20%22MicroFeed%22%2C%20%22appfiles%22%2C%20%22appdata%22%2C%20etc.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20there%20a%20way%20to%20filter%20this%20system%20folder%20out%3F%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20how%20I%20am%20sending%20my%20request%3A%3C%2FP%3E%3CPRE%3Eurl%3A%20appweburl%20%2B%20%22%2F_api%2FSP.AppContextSite(%40target)%2Fweb%2Flists%3F%40target%3D'%22%20%2B%20hostweburl%20%2B%20%22'%22%3C%2FPRE%3E%3CP%3Eand%20later%20I%20am%20using%20this%3A%3C%2FP%3E%3CPRE%3E%24(results).each(function%20()%20%7B%3CBR%20%2F%3E%20items.push('%3CLI%20class%3D%22element%22%3E'%3CBR%20%2F%3E%20%20%20%20%20%2B%20'%3CA%20target%3D%22_parent%22%20href%3D%22'%20%2B%20hostweburl%20%2B%20'%2F'%20%2B%20this.Title%20%2B%20'%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3E'%20%2B%20this.Title%20%2B%20'%3C%2FA%3E'%3CBR%20%2F%3E%20%20%20%20%20%2B%20'%3C%2FLI%3E')%3B%3CBR%20%2F%3E%7D)%3B%3C%2FPRE%3E%3CP%3EAny%20tips%3F%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAmerico%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Regular Contributor

Hi,

How do I get the library URL? 

I tried with ServerRestUrl but I am getting undefined :\ 

 

Best regards

Americo

4 Replies

I managed solve the url thing by creating it manually like this:

 

hostweburl + '/' + this.Title

 

But I noted another problem:

In the site I have created 2 libraries "test" and "test2" but in the result, besides this 2 libraries, I am also getting system libraries like "MicroFeed", "appfiles", "appdata", etc. 

 

I there a way to filter this system folder out? 

 

This is how I am sending my request:

url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists?@target='" + hostweburl + "'"

and later I am using this:

$(results).each(function () {
items.push('<li class="element">'
+ '<a target="_parent" href="' + hostweburl + '/' + this.Title + '">' + this.Title + '</a>'
+ '</li>');
});

Any tips??

 

Americo 

The example above returns information about your file such as the name, full url and the internal “Title”:

rest-select2

For instances where you want to know the “type” of document library it is (example Picture Library vs Document Library), use:

Although some information regarding document libraries require an entirely new endpoint. This includes file paths, subfolders, thumbnails and such.

The above contains an entire new set of information regarding your library.

Hi,

Thanks!

 

There is a little difference with the proposal you posted. I need to get the list of all libraries that is why I am using: 

url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists?@target='" + hostweburl + "'"

without pointing to a specific library.

The result I am getting doesn't contains "EncodedAbsUrl" in the respons.

This is the response for one of the libraries:

 

Skärmklipp.PNG

 

Best regards

Americo

 

 

Hi,

 

If you are using SharePoint Online, you can try the below code for retrieving the Library URL,

 

$.ajax({
        url: hostweburl + "/_api/web/AppTiles?$filter=BaseTemplate eq 101",
        method: "GET",
        headers: { "Accept": "application/json; odata=verbose" },
        success: function (response) {
            var libItems = "";
            $(response.d.results).each(function(){
                libItems +="<li><a href='"+this.Target+"'>"+this.Title+"</a></li>";
            });
            $('#libitems').html(libItems);
            console.log(response);
        alert(response.d.results.length);
        },
        error: function (data) {
            failure(data);
        }
});

SharePoint Online returns the collection of lists, libraries and subsites under the below rest endpoint,

https://<tenant>.sharepoint.com/_api/web/AppTiles

 

 Regards,

Shantha Kumar T