Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

ODATA Web API CRM Online.. How to query more than 5000 records

(0) ShareShare
ReportReport
Posted on by

I am using ODATA Web API and it return only 5000 records using below command. How to get all records from that entity ?

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "api/data/v8.2/products" + queryOptions);

response = await httpClient.SendAsync(request );

myresult = JsonConvert.DeserializeObject<JObject>(response.Content.ReadAsStringAsync().Result);

myresult["value"].Count()

 

*This post is locked for comments

  • Verified answer
    RE: ODATA Web API CRM Online.. How to query more than 5000 records

    Thank you Nilanka for response.

    I am not using XML but plan API calls.

    Here with code I am using and look like using page2Uri validating for remaining pages...

    So far it worked for one entity and will test for other entities.

    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "api/data/v8.2/products" + queryOptions2);

        response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

       if (response.StatusCode == HttpStatusCode.OK) {

           contact1 = JsonConvert.DeserializeObject<JObject>(response.Content.ReadAsStringAsync().Result);

           console.WriteLine(contact1);

           page2Uri = null;

           if ( contact1["@odata.nextLink"] != null )

           page2Uri = contact1["@odata.nextLink"].ToString(); //This URI is already encoded.

           while (page2Uri != null)

           {

              request = new HttpRequestMessage(HttpMethod.Get, page2Uri);

              response = await httpClient.SendAsync(request);

              if (response.StatusCode == HttpStatusCode.OK) //200  {

                 contact1 = JsonConvert.DeserializeObject<JObject>(response.Content.ReadAsStringAsync().Result);

                 console.WriteLine(contact1);

                 if (contact1["@odata.nextLink"] == null)

                     page2Uri = null;

                 else

                     page2Uri = contact1["@odata.nextLink"].ToString(); //This URI is already encoded.

               }

               else

                  page2Uri = null;

             } // end while

         Console.WriteLine("Done with Web API Call '{0}'", DateTime.Now.ToString("h:mm:ss tt"));

     } // end if

  • Suggested answer
    RE: ODATA Web API CRM Online.. How to query more than 5000 records

    Hi Sanjay,

    Can you please look into the below URLs.

    https://softchief.com/2016/02/20/retrieve-more-than-5000-records-in-dynamics-crm/

    https://nishantrana.me/2016/02/11/get-total-count-of-records-in-crm-more-than-5000/

    Thanks 

    Nilanka Sekhar Paul

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,160 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans