Post to API whenever a new row of data appears from our backend database into Retool

As the title says: I have retool populating a table of data from our backend database, and I'd like to push to a separate CRM via API each time a new row of data appears into the table (not from adding the data within retool, but it's being added via another source into our database and then showing up in the Retool table - I'm not trying to edit anything in our backend database). Currently I have the API linked and I can send data from the table, but I can't quite figure out how to trigger it based on a new row of data appearing.

Thanks in advance!

Hi there @rickm :wave:

Happy to help you out here! To confirm, you're wanting to know when a table of yours changes in size, right? It's going to be tough but you'll want to periodically test it's length, I suppose. Am I understanding your issue here correctly?

I have a similar requirement.
My PostGre is updated from services outside of Retool (resource query: channelUpdate).
I also have an update api for slack which sends a specific row from channelUpdate to a Slack Channel(resource query:updateSlackChannel).
Whenever there is an update on my channelUpdate query (new row with a is_active flag =Y), I want to trigger the updateSlackChannel query for that row.

How would you suggest i do this?

Hey @unmukt!

It sounds like you might be able to use a success handler with a potential conditional tossed in:

But it might help to get some more specifics about your flow:

  • Where is the row passed to channelUpdate being pulled from?
  • What response(s) does channelUpdate return when it's called? (e.g. is it an upsert query and you need to check the response to see if a new row has been added)
  • Even though you're using a service outside of Retool to updated your DB is it always being initiated from within Retool?

Hi @Kabirdas, I have a similar situation.

We are creating an app that shows our leads from our website. We would like Retool to send an update when there's a new lead. This update should reflect to our Slack channel. Can you help me with this?

Hey @ajrivera!

Similar to what I mentioned in the post above some context about how exactly you're creating leads would help here :slightly_smiling_face:

If you haven't already, you might want to check out Retool's Workflows product in case you're generating leads from outside Retool as OP mentioned. That allows you to trigger processes via webhooks that you can call from wherever your leads are being generated, you can also set them up to run periodically to monitor for changes in your DB.

Hi @Kabirdas,

  • Where is the row passed to channelUpdate being pulled from?
    /It should pullout from the query we've setup in retool. Here's our flow
    From our website, we created a query that shows all of our leads. What we need now is for those newly added leads, we should be notified via Slack.


Can you share some links that would redirect me to the workflow you're referring to?

Yep! The link is in the post above:

Does that sound like it could work? Otherwise, you'll need to open the Retool app you're building this in to run the queries. Do you currently have a way to distinguish which leads are "new"?

Hi @Kabirdas - Thank you for this. I think workflow is still in beta mode.
Thanks for informing me, I've joined the BETA waitlist.
To distinguish that they are new, we'll have to base it on "created at column"

Got it! You can try running something like

SELECT * FROM leads WHERE created_at > CURRENT_DATE - INTERVAL '1 day';

That should grab all leads created in the past day and you can change the interval to something like '2 days' or '2 hours' if you prefer. From there, you can trigger a query with a success handler that actually makes the necessary posts. This can be either a query that posts all of the leads together at once in a single slack message or something like one of the examples here that triggers your slack query multiple times for each new lead.

There's more documentation on reading from SQL here that might help understand how you can work with your SQL data. We also have documentation here on how to set up a Slack integration.

Let me know what new questions that raises! Also curious to see how you end up building it out :slightly_smiling_face:

1 Like

Thank you for this @Kabirdas! I'll keep you posted :heart:.