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&$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?