Posted by: R Manimaran | October 15, 2014

SharePoint 2013 REST API: Search using HTTP POST

SharePoint 2013 REST API: Search using HTTP POST

SharePoint 2013 provides REST API to do Search. There are two flavors of REST API for Search.

  • One which uses the HTTP GET
  • Second which uses the HTTP POST

Below is the sample to call the Search using the HTTP GET


But the Limitation in using the GET method with querytext is the length of the query string. Max Query text length allowed by the Keyword query is 4096 characters.

In order to overcome this limitations we can use the HTTP Post method to do search.

Resource End Point Url for POST Query: /_api/search/postquery

Below is the syntax of our ajax call to Post query

///method: postquery resource: Microsoft.Office.Server.Search.REST.SearchService
'HitHighlightedProperties':{'results': ['']},
'StrArray':{'results': ['']},
'RefinementFilters':{'results': ['']},

'SelectProperties':{'results': ['']},

'success':function (data) {
       var d = data;
'error':function (err) {

In this example I have placed a textbox and button to do the search. In the button click I have called this REST API call to bring the results using the keyword type in the textbox.

function PostSearch() {
var headers = {
        "Accept": "application/json;odata=verbose",
        "content-Type": "application/json;odata=verbose",
        "X-RequestDigest": jQuery("#__REQUESTDIGEST").val()

var endPointUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/search/postquery";
var searchQuery = {
'request': {
'__metadata': { 'type': 'Microsoft.Office.Server.Search.REST.SearchRequest' },
'Querytext': "'" + $('#txtSearchText').val() + "'",// getting the user feed information from a TextBox
var call = jQuery.ajax({
      url: endPointUrl,
      type: "POST",
      data: JSON.stringify(searchQuery),
      headers: headers,
      dataType: 'json'

call.done(function (data, textStatus, jqXHR) {
var html=[];
var queryResults = data.d.postquery.PrimaryQueryResult.RelevantResults.Table.Rows.results;
   if (queryResults.length > 0) {
       for (var i = 0; i < queryResults.length; i++) {
           var r = queryResults[i];
           var cells = r.Cells;
           var title = '';
           var id = '';
            for (var x = 0; x < cells.results.length; x++) {
            var c = cells.results[x];
               case "LastModifiedTime": id = c.Value; break;
               case "Title": title = c.Value; break;

if (id != '' || title != '') {
else {
    alert("No Results Found");
}); (data) {
    alert("Failure" + JSON.stringify(data));


  1. […] […]

  2. am not able access more than 4000 query length using this postquery

  3. postquery not accepting more than 4096 characters, please suggest.

  4. Post Query character limitation(4000) can be elevated by referring your query in Refinement Filter instead referring it in Query Template or Query Text.

Leave a Reply

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

You are commenting using your 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


%d bloggers like this: