I have a Document library named "My Documents". In that library couple of folders, for these each folders have another couple of folders (subfolders) and inside these folders, certain documents. Requirements are that all these document id must be unique.

Now if I have the document id. How to get perticular document from its id? When the document is found I want the path to that document.

How do I accomplish that using Rest API?


2 Answers 2


Finally i found solution, i got full file url through EncodedAbsUrl

My Document id is 6 and got full filepath from its id

var requestUri = _spPageContextInfo.webAbsoluteUrl +
             "/_api/web/lists/getByTitle('My Documents')/items?$select=EncodedAbsUrl&$filter=Id eq 6";

var requestHeaders = {
    "accept": "application/json;odata=verbose"

    url: requestUri,
    type: 'GET',
    dataType: 'json',
    headers: requestHeaders,
    success: function (data) 
       $.each(data.d.results, function(i,result) {
            var path = result.EncodedAbsUrl;

    error: function ajaxError(response) {
        alert(response.status + ' ' + response.statusText);

For retrieving document(s) by ID, the best approach is to use filter parameter from MS Documentation.


<url_SP_Site>/_api/web/lists/getbytitle('[Name_Document_Library]')/items?$select=Id&$filter=Id eq '[Id_you_search_for]'

If you want to search for multiple documents IDs, you can add and or or operators (I think you have more operators, see the documentation).


<url_SP_Site>/_api/web/lists/getbytitle('[Name_Document_Library]')/items?$select=Id&$filter=Id eq '[Id_you_search_for]' and Id eq '[Another_Id_you_search_for]'
<url_SP_Site>/_api/web/lists/getbytitle('[Name_Document_Library]')/items?$select=Id&$filter=Id eq '[Id_you_search_for]' or Id eq '[Another_Id_you_search_for]'

After that you can use expand parameter with file value to have the relative URL:

[url_SP_Site]/_api/web/lists/getbytitle('[Name_Document_Library]')/items?$select=Id,File/ServerRelativeUrl&$expand=File&$filter=Id eq '[Id_you_search_for]' or Id eq '[Another_Id_you_search_for]'

When you get the response encoded in JSON Format, you can access easily with:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.