I have a standard document library with one added field StudyId (string). I can't figure out how to retrieve files using a filter on that field.

I retrieve files as following:


if I add a filter ?$filter=StudyId eq 123456 I get an error that StudyId field doesn't exist.

For file items fields are returned as properties, so I guess filtering is different, but I can't find out the proper way

Any ideas?

3 Answers 3


This error occurs since filter expression could not be applied for File Collection resource. From another hand, StudyId field is a property of List Item resource and not a File.

Having said that, you could utilize the following query to return File with StudyId set to 123456:

/_api/web/lists/getbytitle('StudyDocuments')/items?$select=File&$expand=File&$filter=StudyId eq 123456 

It is assumed that StudyDocuments is a Documents library title.


Files endpoint doesn't support filtering. Hence you should use CAML query along with REST endpoint

Url -


Body -

    'query' : {
        '__metadata' : { 'type' : 'SP.CamlQuery' },
        'ViewXml' : '<View><Query><Where><Eq><FieldRef Name="StudyId"/><Value Type="Integer">123456</Value></Eq></Where></Query></View>',
        'FolderServerRelativeUrl' : '/tmgt/StudyDocuments'

Libraries in SharePoint are a type of list. So, to query the library you use the same approach as querying a list.

MSDN: https://msdn.microsoft.com/EN-US/library/office/fp142385.aspx

Query the list (library):


For each item returned, get the file properties


One of the properties returned is ServerRelativeUrl

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.