0

Continuing on with my Dynamics 365 from Delphi project, I am now at a point where I need to be retrieving more data from CRM than the 50 entities I can get by default, and that by setting the maxpagesize preference, I should be able to get more.

This is what my existing Delphi code looks like to retrieve the data from Dynamics:

  RESTClient.BaseURL := 'https://mytest.api.crm6.dynamics.com';
  RESTRequest.Resource := 'XRMServices/2011/OrganizationData.svc/AccountSet?$select=Name&';
  RESTRequest.Accept := 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8';
  RESTRequest.Execute;

This returns 50 results, and follows up with the paging tag (which we will ignore for now):

<link rel="next" href="https://mytest.api.crm6.dynamics.com/XRMServices/2011/OrganizationData.svc/AccountSet?$select=Name&amp;$skiptoken=1,'accountid','%7BE5752F29-1E8E-E811-8182-E0071B662BF1%7D','%7B700C44F2-BF8F-E811-8191-E0071B659EC1%7D'" />

https://msdn.microsoft.com/en-us/library/gg334767.aspx#bkmk_specifyNumber

According to the MS documentation above, the request for specifying the number of entities to return looks like this:

GET [Organization URI]/api/data/v8.2/accounts?$select=name HTTP/1.1
Accept: application/json
OData-MaxVersion: 4.0
OData-Version: 4.0
Prefer: odata.maxpagesize=3

The trouble I am having is how to specify the Prefer: odata.maxpagesize=nnn

These are the things I have tried:

  RESTClient.AddParameter('Prefer', 'odata.maxpagesize=250',TRESTRequestParameterKind.pkHTTPHEADER,
    [TRESTRequestParameterOption.poDoNotEncode]);

  RESTRequest.AddAuthParameter('Prefer', 'odata.maxpagesize=250',TRESTRequestParameterKind.pkHTTPHEADER,
    [TRESTRequestParameterOption.poDoNotEncode]);

  RESTRequest.Params.AddItem('Prefer', 'odata.maxpagesize=250',TRESTRequestParameterKind.pkHTTPHEADER,
    [TRESTRequestParameterOption.poDoNotEncode]);

  RESTRequest.Params.AddHeader('Prefer', 'odata.maxpagesize=250');

None of those worked. I still get back 50 entities.

Has anyone else had any success in using the Dynamics 365 Web API from Delphi 10.2, or am I the only one?

SiBrit
  • 1,460
  • 12
  • 39

1 Answers1

1

You are using wrong endpoint, you are calling

https://org/XRMServices/2011/OrganizationData.svc/AccountSet

and you ahould be calling:

https://org/api/data/v8.2/accounts

This is important as the first one is deprecated and you will always get 50 rows there (this can be changed using PowerShell command as described here)

Using the second url (so the new WebAPI which actually supports pagesize) last option should work:

RESTRequest.Params.AddHeader('Prefer', 'odata.maxpagesize=250');
Pawel Gradecki
  • 3,476
  • 6
  • 22
  • 37
  • OMG! I've spent days on this, based on the queries that the company that developed the custom Dynamics 365 application sent me. All the parsing work was done with the results coming back as XML. The CRM 2016 only returns the records as odata, and there is nothing out there for parsing odata in Delphi... – SiBrit Jul 29 '18 at 23:01