Send an email notification when a field changes to a set value from an API workflow

Hi everyone just trying to wrap my head around how I might be able to make this work.

  • I have a data type called devices. These refer to routers.
  • There’s a field called “status” which is either “online” or “offline”
  • I have a endpoint that says “run an API workflow on a list of things”, where the list of things are all devices, and the API workflow it runs makes a GET call to a router management system, returns “online” or “offline” for each device, and updates the “status” field on the device record.
  • I use Integromat to run that API endpoint every 5 minutes
  • This all works fine so far. However what I’m trying to accomplish is a workflow that says “if device status changes from online to offline, send an email” Or “if device status changes from offline to online, send an email” as well as several others that I might want to set up.

Would I create some sort of global workflow that is watching for this field to change? Or how would I do that?

I’m certainly not an expert in this area, but wouldn’t your scenario be the exact kind of thing that database change triggers is designed for? If you haven’t seen this post, check it out and see what you think…

Best…
Mike

1 Like

Sweet thanks I’ll check it out!

1 Like

On a different note, if you want to save 10$/month on Integromat (you are spænding +8000 triggers/month this way), setup an account on AWS, make a simple Lambda Function (if you need i can send you a file) to upload, and make a cronjob in CloudWatch Event.
You get 1.000.000 Lambda Invocations/month for free, so there would be no cost this way.

You can also use Pipedream for a (probably) simpler setup, but haven’t spend much time with that.

3 Likes

That’s an interesting idea! We use AWS today for other things so definitely not impossible. I’d love to see your function as I’ve never used Lambda before but sounds really interesting. Thanks so much!

Sure. Here is a short tutorial :slight_smile:

First you need this file: bubbleCron.zip

Inside is a node.js function plus a dependency called axios that makes it easy to write http requests in node. You could write this without axis (vanilla node), but I just happen to like axios.

Anyway.
To start, go to AWS Console, find Lambda and click Create Function.

Choose Author From Scratch (default) and give the function a name (bubbleCron).
Let runtime be nodejs 12.x and keep standard execution roles.
Click Create Function and wait a bit for it to load.

When its loaded, find the area called Function Code.
Under Code entry type choose ”upload a .zip file” and choose bubbleCron.zip. Then click SAVE in top right corner and the file and code will be loaded.

Now scroll down to the code editor and change the url to your wf-url, and read the notes with //.

When you are ready click test in the top right corner. First time you need to save a test-event. Just give it a random name, click create and then push test again. The code should now run and show you a green message with “Success”. The log output shows a status message which is the message sent from bubble-servers.


In the image I made an initialization, so back in bubble I can see the request data as expected.

When that’s done the cron job should be set up. Head over to Cloudwatch. Choose rules, create rule. Under Event Source choose Schedule and “Fixed rate of” then 5 minutes. On the left pane you choose your target which is the Lambda we just created, so find bubbleCron under function, hit configure, give it a name and click “Create rule”.

Congrats, this cron will run every 5 minutes now. :blush:

With this basic setup you can also do get, post, put etc. to bubble database.

Let me know how it works out for you

6 Likes

Sorry for the delay in responding this is great! I’ll check it out soon and post back!

No luck with this unfortunately as it only works on current plans not legacy ones which I’m on and I don’t want to switch right now as the legacy plans seem much better.

How I would do it, in the api call;
Do the, Status = “Get Online/Offline status”.
Compare Status VS Status Old and send email if different.
Set Status Old = Status

Also, you may want to look into bubble’s limitations with api workflows on lists… essentially, if it runs out of memory during the api calls, it will drop them. The solution is to run one at a time…