This seems to be an aloof question that I can't track down anywhere including here, so I am going to try again to see if someone has a solution. I have a SharePoint 2013 instance that I use the REST API for doing content searches and return to my React front end to display. This works great. However, I now have a problem when I need to only search for a list of specific documents across the whole site not just in a directory or specific list. I can do a content search using the /_api/search/query?queryText="" just fine, but I want to construct the querytext of this API endpoint to only search for doucments within the list I provide.
For example, if I am looking for three documents:
I only want these documents and corresponding data (like the RedirectEmbedURL, etc that I get using the search api) not the /_api/web/lists/getByTitle method.
Is there a way to format the querystring to return only specific files?
Thanks.
To use the REST capabilities that are built into SharePoint, you construct a RESTful HTTP request by using the OData standard, which corresponds to the client object model API you want to use. The client. svc web service handles the HTTP request and serves the appropriate response in either Atom or JSON format.
To retrieve the list you need to know the Site path and the library name.
Also you need operators to work with filters
Operators
Retrieve all Files inside a list: https:////_api/Web/Lists/GetByTitle('')/Items?$expand=File
example:
https://domain-example.com/sites/site1/site2/etc/_api/Web/Lists/GetByTitle('listtitle')/Items?$expand=File
Here are some examples of filters:
To filter by name you need to expand "FieldValuesAsText" and filter by the property "FileLeafRef" Example here:
https://[site]/web/Lists/GetByTitle('[library_name]')/Items?$filter=substringof('[TEXT_TO_SEARCH]',Title) or substringof('[TEXT_TO_SEARCH]',FileLeafRef)&$expand=File,FieldValuesAsText
I'm also filtering by Title as I don't know if the user needs the title or the name with the extension.
Filter StartsWith:
https://domain-example.com/sites/site1/site2/etc/_api/Web/Lists/GetByTitle('listtitle')/Items?$expand=File&$filter=startswith(Title,'Foo')
Filter "Contains" (substringof)
https://domain-example.com/sites/site1/site2/etc/_api/Web/Lists/GetByTitle('listtitle')/Items?$expand=File&$filter=substringof('T15', Title)
Filter "Search with Related key (ex1 in this case)": (substringof)
https://domain-example.com/sites/site1/site2/etc/_api/Web/lists/GetByTitle('listtitle')/Items?$expand=FieldValuesAsText&$filter=substringof('BES10GHC10BB001', ex1)
Thanks for reading!
I just use:
https://<domain>/sites/<list-title>/_api/files
It includes Url, Name and "childrenCount" to filter folders.
You can use logic in the request to filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With