1

We are trying to post a really long query string, that exceeds 2048 characters to sharepoint REST API. I am making a post to the below API

http://sitename/_api/web/sitegroups?$select=LoginName,Id,Title&$Filter=LoginName%20eq%20'Test_Grp'

We modified the config file of our SharePoint site to the below,

     <system.web>
   <httpRuntime maxQueryStringLength="65536"/>

 <system.webServer>
  <security>
   <requestFiltering>
    <requestLimits maxQueryString="65536" />

But still SharePoint throws a 400 error stating that the maxquery length is exceeded. Do I have to change the configurations in some other place?

Is it possible to send the query string as part of the http post body so that the query string length could be let alone ?

2
  • What are you trying to post? Can you share the full URL? Commented Oct 2, 2015 at 3:30
  • I am trying to retrieve a lot of groups. The url contains a lot of $Filter parameters - example - http: //sitename/_api/web/sitegroups?$select=LoginName,Id,Title&$Filter=LoginName%20eq%20'Test_Grp'or%20LoginName%20eq%20'BUADELCI'%20or%20LoginName%20eq%20'BUCENTMKT'%20or%20LoginName%20eq%20'BUADHIIP'%20or%20LoginName%20eq%20'BUAHRWIP'%20or%20LoginName%20eq%20'BUADLPLA'%20or%20LoginName%20eq%20'BUALEXAN'%20or%20LoginName%20eq%20'BUBERRBA'%20or%20LoginName%20eq%20'BUCAMPBE'%20or%20LoginName%20eq%20'BUMNLGRN'%20or%20LoginName%20eq%20'BUBURNIP'%20or%20LoginName%20eq%20'BUCHARIP' Commented Oct 2, 2015 at 3:34

1 Answer 1

4

To avoid this, use CAML query and post it in the request body. Use a CAML query builder to build the query. This doesn't have restrictions on the length. This might become long and repetitive. But AFAIK, there is no other way to post huge request bodies in the request URL.

CAML query:

<Query>
   <Where>
  <Or>
     <Eq>
        <FieldRef Name='Title' />
        <Value Type='Text'>Group 1</Value>
     </Eq>
     <Eq>
        <FieldRef Name='Title' />
        <Value Type='Text'>Group 2</Value>
     </Eq>
  </Or>
   </Where>
</Query>

Sample in JS:

function getDataWithCaml(siteurl, caml) {
var endpoint = siteurl+"/_api/Web/SiteUserInfoList/getitems";
var requestData = { "query" :
   {"__metadata": 
      {"type": "SP.CamlQuery" }
      , "ViewXml": caml
   }
};
return $.ajax({
url: endpoint,
method: "POST",
data: JSON.stringify(requestData),
headers: {
    "X-RequestDigest": $("#__REQUESTDIGEST").val(),
    "Accept": "application/json; odata=verbose",
    "Content-Type": "application/json; odata=verbose"
}
});}    

Usage:

$(document).ready(function(){
var caml = "<View><Query>"+
   "<Where>"+
  "<Eq>"+
     "<FieldRef Name='LinkTitle' />"+
     "<Value Type='Computed'>GroupName</Value>"+
  "</Eq>"+
  "</Where>"+
"</Query></View>";
console.log(caml);
getDataWithCaml("http://siteurl", caml).done(function(data)
{
var resultSet= data.d.results;  
console.log(resultSet);
var title = [];
var id=[];
for(var i=0;i<resultSet.length;i++){
title.push(resultSet[i].Title);
id.push(resultSet[i].ID);
}
console.log(title);
console.log(id);
}).fail(
function(error){
console.log(JSON.stringify(error));
});
});
2
  • Any way of not having to use CAML? Commented May 8, 2018 at 12:58
  • What is it that you're trying to do? Commented May 8, 2018 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.