Search REST API for SharePoint – Multiple use cases


SharePoint Search API is helpful to create a client side webpart. You can build a complete search experience without refreshing the page with the responsive client side search result. To build such webpart fist we need to understand how the REST API and its parameter work. The search REST API will always return the jSON file. We can then use the jQuery api to parse the result and show the search result in the way wanted.

In this blog I will explain few of sample search API used to search documents within the SharePoint. To understand the basics of Search API follow this link https://docs.microsoft.com/en-us/sharepoint/dev/general-development/sharepoint-search-rest-api-overview

Below are some of the API parameters and search use cases in the SharePoint.

Use this url to get text format
Search documents, pages, list items from anywhere with the 20 results, the below query will sort the results in descending order

https://sitecollection/site/_api/search/query?querytext=’*’&sortlist=’LastModifiedTime:descending’&rowlimit=20

Search all sites and everything and return only selected properties in the JSON. Note that the date return will be fixed format you need to convert it to local date time.

https://sitecollection/site/_api/search/query?querytext=’*’&sortlist=’LastModifiedTime:descending’&rowlimit=20&selectproperties=’Title,ModifiedOWSDATE,EditorOWSUSER,Path,ParentLink,FileExtension,FileName,ServerRedirectedEmbedURL’

Search everywhere any documents with the specific extensions only – doc, pdf, excel, powerpoint, txt and mpp files only

https:// //_api/search/query?querytext=’*’&sortlist=’LastModifiedTime:descending’&rowlimit=20&selectproperties=’Title,ModifiedOWSDATE,EditorOWSUSER,Path,ParentLink,FileExtension,FileName,ServerRedirectedEmbedURL’&refiners=’fileextension’&refinementfilters='(fileExtension:or(“docx”,”pdf”,”doc”,”xls”,”xlsx”,”xlsm”,”ppt”,”pptx”,”mpp”,”csv”,”txt”))’

Search documents only from me (My documents anywhere inside SharePoint) my email in below case is senthamilv@outlook.com, searches only by that user id

https:////_api/search/query?querytext=’*’&sortlist=’LastModifiedTime:descending’&rowlimit=20&selectproperties=’Title,ModifiedOWSDATE,EditorOWSUSER,Path,ParentLink,FileExtension,FileName,ServerRedirectedEmbedURL’&refiners=’EditorOWSUSER,fileextension’&refinementfilters=’and(fileExtension:or(“docx”,”pdf”,”doc”,”xls”,”xlsx”,”xlsm”,”ppt”,”pptx”,”mpp”,”csv”,”txt”) , EditorOWSUSER:(Senthamilv@outlook.com))’

Search only my (specific user) documents from specific URL. In below query it searches only from https:///sites/ms/

https:///sites/_api/search/query?querytext=’*’&sortlist=’LastModifiedTime:descending’&rowlimit=20&selectproperties=’Title,ModifiedOWSDATE,EditorOWSUSER,Path,ParentLink,FileExtension,FileName,ServerRedirectedEmbedURL’&refiners=’EditorOWSUSER,fileextension,Path’&refinementfilters=’and(Path:”https:///sites/ms/*”,and(fileExtension:or(“docx”,”pdf”,”doc”,”xls”,”xlsx”,”xlsm”,”ppt”,”pptx”,”mpp”,”csv”,”txt”) , EditorOWSUSER:(Senthamilv@outlook.com) ))’

Search all my documents from One Drive only

https:////_api/search/query?querytext=’*’&sortlist=’LastModifiedTime:descending’&rowlimit=20&selectproperties=’Title,ModifiedOWSDATE,EditorOWSUSER,Path,ParentLink,FileExtension,FileName,ServerRedirectedEmbedURL’&refiners=’EditorOWSUSER,fileextension,Path’&refinementfilters=’and(Path:”https://mysite..com/personal*”,and(fileExtension:or(“docx”,”pdf”,”doc”,”xls”,”xlsx”,”xlsm”,”ppt”,”pptx”,”mpp”,”csv”,”txt”) , EditorOWSUSER:(Senthamilv@outlook.com)))’

Search all documents modified by (name *)

https://<sitecollection//_api/search/query?querytext='ModifiedBy:senthamil*'&sortlist='LastModifiedTime:descending'&rowlimit=20&selectproperties='Title,ModifiedOWSDATE,EditorOWSUSER,Path,ParentLink,FileExtension,FileName,ServerRedirectedEmbedURL'&refiners='fileextension'&refinementfilters='(fileExtension:or("docx&quot;,"pdf","doc","xls","xlsx","xlsm","ppt","pptx","mpp","csv","txt"))'

Search documents from your team members (peers and manager). For this search you can first find all your team members using my other blog here. Once the team member email addresses are known, those emails can be used as search refiners.

https:////_api/search/query?querytext=’*’&sortlist=’LastModifiedTime:descending’&rowlimit=20&selectproperties=’Title,ModifiedOWSDATE,EditorOWSUSER,Path,ParentLink,FileExtension,FileName,ServerRedirectedEmbedURL’&refiners=’EditorOWSUSER,fileextension’&refinementfilters=’and(fileExtension:or(“docx&#8221;,”pdf”,”doc”,”xls”,”xlsx”,”xlsm”,”ppt”,”pptx”,”mpp”,”csv”,”txt”) , EditorOWSUSER:or (senthamilv@outlook.com,ananana@hotmail.com))’

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: