I am using this approach https://msdn.microsoft.com/en-us/library/gg309717.aspx to retrieve more than 5000 records. I am using MS Dynamics REST API together with fetchXML. My first request looks like this:
//ROOT.dynamics.com//api/data/v8.1/contacts?fetchXml=<fetch
version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="contact"><attribute name="emailaddress1" /></entity></fetch>
as a result I got set of records and page cookie for next page: "@Microsoft.Dynamics.CRM.fetchxmlpagingcookie":"<cookie
pagenumber=\"2\" pagingcookie=\"%253ccookie%2520page%253d%25221%2522%253e%253ccontactid%2520last%253d%2522%257bAF17816D-3AAE-E511-80FC-1458D043A570%257d%2522%2520first%253d%2522%257bFF672EF5-22AE-E511-80FC-1458D043A570%257d%2522%2520%252f%253e%253c%252fcookie%253e\"
istracking=\"False\" />"
I am using this cookie in next request: //ROOT.dynamics.com//api/data/v8.1/contacts?fetchXml=<fetch
mapping='logical' paging-cookie='<cookie page="1"><contactid last="{UUID}" first="UUID}"/></cookie>' page='2'><entity name='contact'><all-attributes/></entity></fetch>
and got {
Message: "An item with the same key has already been added.", ExceptionMessage: "An item with the same key has already been added.", ExceptionType: "System.ArgumentException", StackTrace: " at System.ThrowHelper.ThrowArgumentException(ExceptionResource
resource) at System.Collections.Generic.Dictionary
2.Insert(TKey key, TValue value, Boolean add) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1
source, Func
2 keySelector, Func2
elementSelector, IEqualityComparer
1 comparer) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable1
source, Func
2 keySelector, Func2
elementSelector) at Microsoft.Crm.Extensibility.OData.CrmODataHeaders.ProcessVersioningQueryParameters() at Microsoft.Crm.Extensibility.OData.CrmODataHeaders..ctor(HttpRequestMessage request) at Microsoft.Crm.Extensibility.OData.Extensions.EdmExtensions.GetCrmODataRequestHeader(HttpRequestMessage
request) at Microsoft.Crm.Extensibility.OData.CrmODataRoutingConvention.SelectController(ODataPath odataPath, HttpRequestMessage request) at System.Web.OData.Routing.ODataPathRouteConstraint.SelectControllerName(ODataPath path, HttpRequestMessage request)
at System.Web.OData.Routing.ODataPathRouteConstraint.Match(HttpRequestMessage request, IHttpRoute route, String parameterName, IDictionary
2 values, HttpRouteDirection routeDirection) at System.Web.Http.Routing.HttpRoute.ProcessConstraint(HttpRequestMessage
request, Object constraint, String parameterName, HttpRouteValueDictionary values, HttpRouteDirection routeDirection) at System.Web.Http.Routing.HttpRoute.ProcessConstraints(HttpRequestMessage request, HttpRouteValueDictionary values, HttpRouteDirection routeDirection)
at System.Web.Http.Routing.HttpRoute.GetRouteData(String virtualPathRoot, HttpRequestMessage request) at System.Web.Http.WebHost.Routing.HttpWebRoute.GetRouteData(HttpContextBase httpContext)", ErrorCode: 500 }`
This fetcXML works well inside of this tool http://msxrmtools.com/fetchxml but not for pure REST API request. Maybe I have some issue with encode or structure of URL.