Table to receive data from POST API

Hi!

Is there a method to have a Table component receive data from an external POST API? In other words, the table is empty but when I send data through a POST call to that endpoint, it populates the table.

The Table might create an underlying POST API endpoint corresponding to the columns in the Table and I would be able to send data from externally (e.g. Postman) to that POST API which would then populate the Table?

Thanks!
Thomas

2 Likes

Hello @thomasww!

Unfortunately, Retool apps cannot receive REST API calls :sweat:

The only inputs that they work with are user events. On the other hand, workflows do have an option to set their triggers to be API calls to the webhook URL they create.

This allows webhooks to receive data payload and perform logic in code blocks and additional queries. The only way to get data into a table would be to POST the data to a database, then use a resource of that data base along with a query to fetch this data and display it in a table.

1 Like

Thanks @Jack_T!

Is there then a way to query a GET API call based on a user event for a limited time. I.e. in a loop of, e.g., 1 minute every 10th second - and ideally with a break clause if the GET call response includes a certain key/value pair? And a follow-up questions: can I store that "state" to show the users that we're polling that endpoint?

No problem!

I think it should be possible to do what you are describing.

JS code in blocks can use async/await to await the response of an Query call, and queries can be called in JS blocks using the .trigger() method.

Also here are some docs on running a query periodically. although this run behavior might be tricky to switch off when you don't want it to run anymore, these docs do have a lot of details about setting up query behavior.

As well as the timer component which can be set to run a query when it expires and then in that query's success/failure behavior you can set the timer again if needed or proceed to other logic if the data you are polling is what you want. This could be created and triggered by a user event and ended when logic dictates.

I haven't played around this break statements yet but they could work as well inside a for loop in a JS query block. Would be curious to hear about how testing this option goes.

For the state question, yes this is very easy. You can create a variable from the query creation options and display this to the user in another component, by setting the components source to be the variable and the method .setValue() to mutate this with new data that is returned by other queries!

1 Like