I am using the REST API for Oracle Fusion Cloud HCM which is returning me data in a paged manner. Though now I am stuck on how I get the next batch.
Here is a screenshot of the data I am getting from the very first call:
Here is my code
<cfparam name="variables.offset" default="0">
<cfparam name="variables.limit" default= "25">
<cfparam name="variables.hasMoreData" default="true">
…
<cfif variables.hasmoreData eq true>
<cfset variables.offset = variables.resultData.data.offset + 1>
<cfset variables.limit = variables.resultData.data.totalResults - variables.resultData.data.limit>
</cfif>
The problem seems to be in the bottom section where I am unable to determine the next offset to get the next batch until it reaches the end of the total records.
The API obviously uses the parameters offset
and limit
to paginate the returned data.
offset
is zero-based and defines the starting position of the returned data. And limit
restricts the maximal number of returned results and by that represents the number of items per page.
So setting offset
to offset + 1
for the next call is wrong. You need to increase it by the batch size, i.e. you need to add limit
to it. As the number of items per batch normally isn't expected to change, limit
should stay unchanged.
Therefore, the code to increase the offset might rather look like this:
<cfset variables.hasMoreData = variables.resultData.data.offset lt variables.resultData.data.totalResults>
<cfif variables.hasMoreData>
<cfset variables.offset = variables.resultData.data.offset + variables.resultData.data.limit>
</cfif>