How to store multiple pages of API results in one Query?

Hello everyone,

Let me describe my scenario:

  • Using Jira REST API,
  • Fetching the list of Jira issues from one of the key endpoints,
  • The maximum page size the API supports is 100, which is less than I need to have available “locally”.

I am looking for a best practice that would allow me to execute this AppSmith Query multiple times, fetching all the pages I need (I assume 2-10 pages in total), and store them somehow for future usage. Intuitively, perhaps there is a way to add to the Query data multiple times from multiple calls (using logic in some JS Object), or use some sort of local storage.

One thing I explicitly cannot do is to use the server-side paging on top of some Table widget: I really need to have all N pages of Jira API results present locally to do additional aggregations on them.

Thanks in advance!

Hi there!

One thing i can think of right now is to use a Promise.all() for the queries, when the result gets returned, you can merge them together and then perform whatever aggregation you want.

Does this help?

Hello Olawale, thanks for getting back to me on this topic!

Let me see if I understand your idea right: you propose to use Promise.all() to make sure that all the queries are run in series, and then continue working with the result? This would be something I would set up on the level of the Query or some JS Object?

I should perhaps clarify how the Jira issues API works:

  • I need to specify the query by which I am searching the issues (this works fine, no trouble here).
  • I may specify the maximum page size I want (but I will never get more than 100 results).
  • I may specify a startAt parameter to drive the pagination.

As a result, I get a JSON with an array of issues, and also the total number of records, and how many I was actually given.

(Here is the documentation https://developer.atlassian.com/cloud/jira/platform/rest/v2/api-group-issue-search/#api-rest-api-2-search-get)

It feels that I should have a JS Object that would do the following:

  • Run the Jira Query for the first time to discover the total number of records,
  • Figure out, how many times do I need to call the API to get all of them (something like ceil(total / 100)),
  • And in a loop run the Query with incrementally larger startAt parameter.

To me this sounds like it could work, but I’d like to understand:

  • Does it sound like the proper way to do it to you? I am looking for a best-practice approach, so if you feel I should be doing it differently, please let me know!
  • How can I trigger the Query from a JS Object multiple times, each time with a different parameter value?

Thanks a lot in advance!

Hi again!

  1. Yes, I propose you use Promise.all(). The reason for this is so that you can run the queries multiple times and you get all the results at once.

  2. Overall, I don’t think it’s a bad Idea to run the queries multiple times. You can probably call this query as many times as you like, but keep in mind that the more queries you have, the slower your app gets. If a query returns 100 results and you run it 3 times, you will have about 300 results to work with. This means that if you’re looping through them, you’ll have a loop that runs 300 times. In my opinioin, you shouldn’t do this for total results > 500.

  3. You can achieve this by running this query within a JsObject. For instance, say you have a query called GET_ISSUES_FROM_JIRA, within your JsObject, you can call this query and send parameters like this: GET_ISSUES_FROM_JIRA.run({param1: 'value1', param2: 'value'}) . Within your query, you can reference the parameters like so: {{this.params.param1}} .

Let me know if you need me to clarify anything.

Hello again Olawale,

thanks, the point 3. is exactly what I was missing! Will build the query this way, I am confident it will work.

Thanks again for pointing me in the right direction!

Thanks for your continuous support and patience. We hope your issue is resolved now.

Let us know how did we do?
https://survey.frontapp.com/v2/09a400bf433bc9676d67/f0cb8692d6bdd5efc40fb2bbafe7a43f