Forum Discussion

smeetsh's avatar
smeetsh
Continued Contributor
1 year ago
Solved

using pagination to pull data from a REST api

Hi All,   I am using a pipeline in fabric to pull data from an API. In itself a simple task but the API is paginated and I can't get the copy activity to cycle through it correctly. my relative ...
  • smeetsh's avatar
    1 year ago

    I managed to sort it out (in this scenario anyway). In the json response there are links to "next page"

     

    In my json array 

     

    there is an array named "links" and in that array is a key/value pair "next" The key  "next" stores the actual link to the next page, and if there is no more next page it will have a value null.

     

    As an example:

    -----

    "links": {
            "first": "https://myurl/api/v1/events?page=1",
            "prev": null,
        },

    -----

     

    If the api response has this (and from what I can gather it is actually a standard), the solution for pagination is very simple. Under the pagination rules you have to enter the following

    The thing I couldn't figure out (and copilot completely missed it) is that you use AbsoluteUrl, you leave the next column blank and under value you choose body with that value in my case links.next. Links comes from the array name "links",  and "next" is the key that holds the url for the next page, and if there is no more next page it becomes null, and the copy activity will end.

     

    As another example: if the array name had been pagination and the key next_page, then the value would have been "pagination.next_page"

    I hope this helps others to handle pagination. If your json response does not have an array  for pagination like mine had. It really becomes dependant on what the API is capable of and that could mean some how storing the last page value in in variable and looping through it.

    Cheers

    Hans