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 ?

  • What are you trying to post? Can you share the full URL? – Akhoy Oct 2 '15 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' – jkr Oct 2 '15 at 3:34
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));
});
});
  • Any way of not having to use CAML? – Christoph Bühler May 8 '18 at 12:58
  • What is it that you're trying to do? – Akhoy May 8 '18 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.