Reputation: 1
I have created a copy data activity in azure data factory and this data pipeline pulls the data from an API (via REST activity source) and writes the response body (json) on a file kept in the azure blob storage. The API which I am fetching the response from, is paginated and the link to next page is sent in the response headers in response->headers->link.
This URL to next page is in the following general format:
<https%3A%2F%2FsomeAPI.com%2Fv2%2FgetRequest%3FperPage%3D80%26sortOrder%3DDESCENDING%26nextPageToken%3DVAdjkjklfjjgkl>; rel="next"
I want to fetch the next page token present in the above URL and use it in the pagination rule.
I have tried using some pagination rules:
> AbsoluteURL = Headers.link
But, this did not work as the entire encoded link shown above, is getting appended directly and hence, the pipeline throws an error.
I have also tried to use the query parameters but could not get any result.
I have followed questions on Stack Overflow and have read the documentation:
How can I access this next page token? What pagination rule is needed support the scenario?
Pasting postman output and ADF data pipeline, for reference.
Postman Response Headers Output:
Pagination Rules, I need help on:
Upvotes: 0
Views: 1412
Reputation: 8382
AFAIK, there is no direct option to decode the URL in ADF paginating rule.
You can follow below approach:
First take a set variable and create temp
variable as string and value as 1
Then take until activity and give the condition as @equals(variables('temp1'),10)
so it will iterate over it till condition matches.
Under the until loop take another set variable and create variable URL1
as string and value as URL of rest api.
After this pass variable value to copy activity and copy the first page to destination.
After this take web activity and pass that URL variable to it and get response headers.
After this take set variable and update the URL to next page url usnig dynamic expression.
@uriComponentToString(split(split(activity('Web1').output.ADFWebActivityResponseHeaders["link"],'>')[0],'<')[1])
In last create a variable called increment as string and increment initial temp variable for every iteration by @add(int(variables('temp1')),1)
By this process you can copy as many pages as you want or you set in Until loop as we don't have any specific condition to terminate loop.
Upvotes: 0
Reputation: 9
My team adopted Pratik's approach with one caveat, we set variable 3 to be outside of the Until activity. Otherwise we would keep overriding url1 value every run.
Our ADF pipeline:
Upvotes: 0