Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any direct way to get the server relative URL of document library using its title using Rest API?

Presently I am using the following method to get the server relative URL

function getLibraryUrl(nameOrUrl)
    {
        var ctx = SP.ClientContext.get_current();
        var list = ctx.get_web().get_lists().getByTitle(nameOrUrl);
        ctx.load(list,'RootFolder');
        ctx.executeQueryAsync(
                            function(){
                            var url=list.get_rootFolder().get_serverRelativeUrl();
                            return url;
                            },
                            function(sender, args)
                                    {

     });    
    }

But, I don't want to use the asynchronous call. Can any one please guide me to get the server relative URL of document library using rest API.

Something like this /_api/Web/Lists/getByTitle('')/items?$select=File/ServerRelativeUrl&$expand=File

like image 431
Keerthi Kumar Avatar asked Sep 11 '25 10:09

Keerthi Kumar


1 Answers

Yes you can get ServerRelativeUrl of document library using REST API.

Refer below REST URL :

https://abcd.sharepoint.com/sites/RohitW/_api/Web/lists/getbytitle('DocLibTest1')/RootFolder

Output :

enter image description here

like image 79
Rohit Waghela Avatar answered Sep 14 '25 04:09

Rohit Waghela