I have a long $filter query like ID eq 1 or ID eq 2 or ID eq 33 or ID eq ... and it works like a charm when we have up to 159 conditions joined by or.

But, when I add one more condition (started from 160) I have an error:

{"error": {
"code": "-2147024809, System.ArgumentException",
"message": {
  "lang": "en-US",
  "value": "Value does not fall within the expected range"

There is no problem with ID - condition can be like ID eq 1 or ID eq 1 ... - the issue occupied only with count of conditions.

In SP logs I see following:

    System.ArgumentException: Value does not fall within the expected range, StackTrace:   
in Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData()    
in Microsoft.SharePoint.SPListItemEntityCollection.TryWriteAsOData(ServerStub serverStub, ODataWriter writer, RESTfulQuery query, ProxyContext proxyContext)    
in Microsoft.SharePoint.Client.ServerStub.Write(Object value, Uri path, ODataWriter writer, RESTfulQuery query, ProxyContext proxyContext)    
in Microsoft.SharePoint.Client.Rest.RestRequestProcessor.Process()    
in Microsoft.SharePoint.Client.Rest.RestRequestProcessor.ProcessRequest()    
in Microsoft.SharePoint.Client.Rest.RestService.ProcessQuery(Stream inputStream, IList1 pendingDisposableContainer)    
in Microsoft.SharePoint.Client.ClientRequestService.ProcessRestQuery(Stream inputStream)    
in SyncInvokeProcessRestQuery(Object , Object[] , Object[] )    
in System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)    
in System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)    
in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc& rpc)    
in System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc)    
in System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)    
in System.ServiceModel.Dispatcher.ChannelHandler.DispatchAndReleasePump(RequestContext request, Boolean cleanThread, OperationContext currentOperationContext)    
in System.ServiceModel.Dispatcher.ChannelHandler.HandleRequest(RequestContext request, OperationContext currentOperationContext)    
in System.ServiceModel.Dispatcher.ChannelHandler.AsyncMessagePump(IAsyncResult result)    
in System.ServiceModel.Dispatcher.ChannelHandler.OnAsyncReceiveComplete(IAsyncResult result)    
in System.Runtime.Fx.AsyncThunk.UnhandledExceptionFrame(IAsyncResult result)    
in System.Runtime.AsyncResult.Complete(Boolean completedSynchronously)    
in System.Runtime.InputQueue1.AsyncQueueReader.Set(Item item)    
in System.Runtime.InputQueue1.EnqueueAndDispatch(Item item, Boolean canDispatchOnThisThread)    
in System.Runtime.InputQueue1.EnqueueAndDispatch(T item, Action dequeuedCallback, Boolean canDispatchOnThisThread)    
in System.ServiceModel.Channels.SingletonChannelAcceptor3.Enqueue(QueueItemType item, Action dequeuedCallback, Boolean canDispatchOnThisThread)    
in System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.CompleteParseAndEnqueue(IAsyncResult result)    
in System.ServiceModel.Channels.HttpPipeline.EnqueueMessageAsyncResult.HandleParseIncomingMessage(IAsyncResult result)    
in System.Runtime.AsyncResult.SyncContinue(IAsyncResult result)    
in System.ServiceModel.Channels.HttpPipeline.EmptyHttpPipeline.BeginProcessInboundRequest(ReplyChannelAcceptor replyChannelAcceptor, Action dequeuedCallback, AsyncCallback callback, Object state)    
in System.ServiceModel.Channels.HttpChannelListener1.HttpContextReceivedAsyncResult1.ProcessHttpContextAsync()    
in System.ServiceModel.Channels.HttpChannelListener1.BeginHttpContextReceived(HttpRequestContext context, Action acceptorCallback, AsyncCallback callback, Object state)    
in System.ServiceModel.Activation.HostedHttpTransportManager.HttpContextReceived(HostedHttpRequestAsyncResult result)    
in System.ServiceModel.Activation.HostedHttpRequestAsyncResult.HandleRequest()    
in System.ServiceModel.Activation.HostedHttpRequestAsyncResult.BeginRequest()    
in System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequest(Object state)    
in System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state)    
in System.ServiceModel.Activation.HostedHttpRequestAsyncResult.OnBeginRequestWithFlow(Object state)    
in System.Runtime.IOThreadScheduler.ScheduledOverlapped.IOCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped nativeOverlapped)    
in System.Runtime.Fx.IOCompletionThunk.UnhandledExceptionFrame(UInt32 error, UInt32 bytesRead, NativeOverlapped nativeOverlapped)    
in System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)  

I read lots of documents about SP limitations bud didn't found any point about limit of conditions count.

Please help

UPDATE: URL length is not a problem - the same issue can be with much more longer url (like VeryLongFiedName eq 123456 or VeryLongFiedName eq 123456 ...). If I have 159 conditions like VeryLongFiedName eq 123456 joined by or it works, but if there are 160 conditions it returns the error

  • Please go through this answer which is in similar context. sharepoint.stackexchange.com/a/194328/40602
    – Yayati
    Apr 16 '19 at 11:35
  • 1
    There is no item about this limitation. URL length is not a problem - the same issue can be with much more longer url (like VeryLongFiedName eq 123456 or VeryLongFiedName eq 123456 ...). If I have 159 conditions like "VeryLongFiedName eq 123456" joined by "or" it works, but if 160 it returns error.
    – darknos
    Apr 16 '19 at 12:31

Generally you shouldn't query with so many conditions unless it is really necessary. Following is a workaround which you can try.

If there are limitations in REST api multiple query conditions then you might think of using caml query IN operator in REST API.

function restCallwithCaml(listName, caml) {  
    /// get the site url  
    var siteUrl = _spPageContextInfo.siteAbsoluteUrl;  
    /// set request data  
    var data = { "query" :{"__metadata": { "type": "SP.CamlQuery" }, "ViewXml": caml}};  
    /// make an ajax call  
       url: siteUrl+"/_api/web/lists/GetByTitle('"+ listName +"')/GetItems",  
            method: "POST",  
            data: data,  
            headers: {  
               "X-RequestDigest": $("#__REQUESTDIGEST").val(),  
               'content-type': 'application/json;odata=verbose',  
               'accept': 'application/json;odata=verbose'  
            success: function (response) {  
            ///do your code  
            error: function (data) {  
            ///do your code  

You can define caml query like this to have more than 500 conditions.

        <FieldRef Name='ID'/>
        <FieldRef Name='Title'/>
                    <FieldRef Name='ID' />
                        <Value Type='Integer'>1</Value>
                        <Value Type='Integer'>2</Value>
                        <Value Type='Integer'>3</Value>
                        <Value Type='Integer'>499</Value>
                    <FieldRef Name='ID' />
                        <Value Type='Integer'>500</Value>
                        <Value Type='Integer'>501</Value>
                        <Value Type='Integer'>502</Value>
                        <Value Type='Integer'>999</Value>

SharePoint REST API - CAML Query

  • maybe it depends on your server setup, but in my on-premise installation I had the limit set as 60, not 500. Also, if you have more Value criteria than your limit, you'll need to start nesting <OR> tags
    – Jose R
    Jul 28 '20 at 18:00

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.