Reputation: 45
I am using ADF to retrieve data from a REST API and loading into an SQL DB. The problem I have is that the endpoints in the API return a max of 50 records per page.
I'm trying to use the built-in pagination in ADF by setting Pagination rules with QueryParameters, {offset} using range and the max value.
Some endpoints in the API does return total rows in the call. So I could possibly use this somehow to make the Copy Data activity dynamic.
The relative URL i use is:
@concat(
pipeline().parameters.relative_url,
'?offset={offset}'
)
And the {offset} in Pagination Rules is set up as:
@concat(
'RANGE:0:',
activity('LookUp_Total').output.firstRow.Total,
':50')
The problem I encounter is with endpoints where the total is larger than 50 I get duplicates. So if the total is for example 76 I still get 100 records.
Upvotes: 0
Views: 2158
Reputation: 523
Assuming this type of pagination object in your payload:
I implemented it using a foreach that iterates through a paging array. Here is the general structure:
Let's discuss each activity:
get oauth token - retrieve the bearer token required for API authentication.
first call for paging info - call the api specifically to retrieve the first pagination object.
create paging array - for the Name field: create a Pipeline variable of type Array called paging_array. For the Value field: use the @range function to build the array, representing the number of calls that need to be made to the API based on the limit and total number of records to be retrieved:
@range(
1,
add(
div(activity('first call for paging info').output.pagination.total, activity('first call for paging info').output.pagination.limit),
if(
equals(mod(activity('first call for paging info').output.pagination.total, activity('first call for paging info').output.pagination.limit), 0),
0,
1
)
)
)
https://your.excellent.api/v1/users?limit=100,offset=@{item()}
Watch your batch count so your API is not overwhelmed, especially in the scenario where your doing an initial full load and then subsequent deltas...
Thank you!
Douglas
Upvotes: 0
Reputation: 689
limit
and an offset
.You can walk through the full syntax and code here.
SO - Azure Data Factory Pagination with offset.
Upvotes: 0