Rest api next url

How do i get this to work, i did not find any "native" pagination methods/fields in rest api configuration in order to "loop" trough the "next_url" in the api response.

It seems there are many threads regarding "table component server-side pagination but did not find any regarding the good'ol rest api call.

Thanks in advance!!

-Kimi-

Hello!

I think you can accomplish this with a custom JS Query which triggers an API query asynchronously. You'd be triggering the API within a loop (a while-loop, most likely) and only completing the loop when next_url is null (or missing from the return data). You may want to have an initial query (firstQuery) that is run which then triggers this loop (when the response data contains next_url This would probably look a little something like:

let aNextUrl = firstQuery.data.next_url;
let limitValue = 10000;
let allResults = firstQuery.data;
let next = true;
while (next)
{
    const resp = await yourNextAPIQuery.trigger({
        additionalScope: {
            nextUrl: aNextUrl,
            limit: limitValue
        }
    });
    if(resp.data.next_url) { 
        aNextUrl = resp.data.next_url; 
        allResults.push(resp.data);
    }
    else { next = false; }
}
return allResults;

You'll have to setup the triggered API query to use whatever additionalScope variables you send and then use those in the URL params of the query. Using the ones above, you'd have {{nextUrl}} and {{limit}} in the spots you need to use that data.

Thanks pyrrho! :slight_smile:

I ended up doing this with python block in a workflow, but similar idea you had.

btw, why there is no python block/queries available in the app builder, only in workflow, do you have any idea?

btw2: is there any "native" way to trigger app queries after a workflow has run? Example: workflow put data in retoolDB --> in the app there is a table which i just want to refresh after the workflow has run.

-Kimi-

I don't believe this was on the roadmap for the Apps as of last year but I'm not sure about the current plans to make this available in an App. Going through a workflow is the usual path, which leads to your btw2:

In your workflow you can setup a response node to send back data to the triggering app. In your workflow query you set up a success event handler to then trigger the refreshed data sources.

Regarding btw2:

How do actually do that?

Let's say i have the response node ending my workflow what do i put there and how do i utilize that in the app?
image

Sorry about these noob questions but i'm a noob with retool :slight_smile:

We all start from scratch and make our way from there!

I think you need to use the key of your return object without string-ing it when in this node:

{
   ta: "daa"
}

Then, back in your App, you'll get the response from your workflow when you trigger it and setup the Event handler for success:

1 Like

Ok, got it :slight_smile: Now it works!!

Thank you very much for your help.

The thing which threw me off was:

if there is NO response node in the workflow the app query is "success" when it manages to run itself, ie. start the workflow --> too early for table refresh

if there IS response node in the workflow the app query is "success" when it gets a response, ie. in the end of the workflow --> correct time to do table refresh

2 Likes