querying document libraries using SharePoint REST

Published on Friday, 31 January 2020

today I needed to query a document library using the REST api. I found that simply calling _api/web/list/getbytitle('foo')/items would not return me either the filename or full path.

The secret is to call FieldValuesAsText - here FileRef (the server relative path) and FileLeafRef are present. One can either call it directly or expand it. Additionally, it is possible to get a nice Icon to display.

See lines 1,2 and 3 respectively:

size in line 3 can be 0 or 1 - for small or large images respectively.

The Doumentation for this can be found at SP.Web.mapToIcon and SP.ListItem.fieldValuesAsText.