Button Script - Trigger API call, Poll Response and display loading will polling

Hi there and welcome,

There's many ways that this can be achieved but it can get complicated pretty quickly too. My preference is to unlink the first action and the second action as much as possible and have them run as independent actions.

So, I'd have a POST query that sends the request to the first endpoint and stores the returned ID in a variable, that makes it available to other actions and the first query doesn't need to worry about what they do with it.

A second query to GET the completed document would "Run the query periodically" ( you can do this in the advanced tab of the query )
This second query should be disabled (again, in the advanced tab) if there isn't an ID to be requesting OR if the request has been fulfilled.

I've made a basic example for you to play with to try to explain it better.
Pressing the Post Message button will clear all old requests and trigger the insert query - this sends a UUID to the server and returns the id of the request which it saves in a variable.
When this variable is updated it makes the second query try to GET the UUID using the inserted id and it will repeatedly run until that response has been received.
A loading indicator will spin while either query is active.

Hope this gives you some ideas of how to proceed, but as I said there are multiple ways to solve this one.

forum.json (15.1 KB)

1 Like