powerbijirajira-rest-apijira-rest-java-api

Jira Atlassian API Pagination


I've used the JIRA API a few timees, but only for small extracts so I've never had to use pagniation to return more results than the max result.

Here's the documentation for the API: https://developer.atlassian.com/cloud/jira/platform/rest/v3/#expansion

I have a query to the API:

let


Source = Json.Document(Web.Contents("*connection URL*,
[Headers=[Accept="application/json"]])),


#"Converted to Table" = Table.FromRecords({Source}),


>Expand the scheme, and define the field data types etc


in

 
#"Changed Type"

I can see form the documentation I need to use something like this:

{

    "startAt" : 0,

    "maxResults" : 10,

    "total": 200,

    "isLast": false,

    "values": [

        { /* result 0 */ },

        { /* result 1 */ },

        { /* result 2 */ }

    ]

}

I'm not sure where the pagination would fit into this? Can anyone help me? I need to return 1500 results.

Thanks


Solution

  • You'll need to make multiple REST requests that iterate through all of the results one "page" at a time:

    1. Read the API response from JIRA and capture the values of maxResults and startAt in the response.
    2. Add the value of maxResults to startAt, update your REST API call startAt parameter, and call the same API endpoint again.
    3. Repeat until startAt is greater than or equal to total, or until isLast is true.

    A while loop is a natural fit for an operation like this. To minimize API calls, you should use a larger value for maxResults so you receive more data in each loop.