Get Document Path (ServerRelativeUrl) in SharePoint 2013 using REST API

Suppose we have a document in document library in SharePoint 2013 inside sub folders

Ex: /En/Documents/Folder1/Folder2/stats.png

Now, using REST API we need to get the Server Relative Url (ServerRelativeUrl) by the document ID.

Solution

The REST API url will be: http://<server name>/<sub site>/_api/web/lists/getbytitle(‘Documents’)/items(‘<Document ID>’)/File

In my case it will be : http:// <server name>/En/_api/web/lists/getbytitle(‘Documents’)/items(‘5‘)/File

Result

OData in SharePoint 2013 – Lists and Items

I will explain below the most common GET operations which most of developer may need them while query SharePoint 2013 lists and list items using REST.

  • Get all lists in web

  • Get all list by title

  • Get all items in specific list
    • Request: http://<server>/_api /web1/web2/lists/GetByTitle(‘myList’)/items
    • Result: the below screen shows one item Meta Data in the response

  • Get list item by item ID
    • Request: http://<server>/_api /web1/web2/lists/GetByTitle(‘myList’)/items/GetItemById(4)
    • Result:

  • Return items with specific fields
    • Request: http://<server>/_api /web1/web2/lists/GetByTitle(‘myList’)/items?$select=Title,Age
    • Result:

  • Order items in the query

 

For more information: