Overconsumption Alerting Example (with N8N)
When one of your customers is overconsuming during a period, you might need to warn her. This might happen for Cloud or API products. Automatic billing does not mean that your customers should have a bad surprise when opening their invoices. Here is a full workflow to create an alerting system based on your customers’ current usage, using N8N, a powerful automation tool for developers.
N8N Alerting Workflow
- Use a Cron expression to call the Lago API every X minutes/hours/days
- Call the Current usage endpoint available in Lago to fetch your customers’ current usage;
- Create a IF statement to condition the trigger (in our case, messages are triggered above a specific overconsumption); and
- Send a message whenever this threshold is reached. You could use an emailing tool, Slack or a CRM. In our case, we are using Slack.
1st Node - CRON expression to repeat tasks at a defined interval
The first node is repeatedly and automatically triggering the automation at a defined interval.- Add a new Node;
- Select CRON as a new application node;
- The Mode is set to
Every X; and - The Value is defined to
10and the the Units tominutes.

Cron expression
2nd Node - Catch customers’ current usage with a HTTP Request
This node is used to fetch current usage from Lago API, using a HTTP request.- Add a new Node;
- Select HTTP Request as a new application node;
- Fetch customers’ current usage from Lago API;
- Make sure to set the
API_KEYand theContent-Typeas headers of your request; and - Execute the node to fetch the payload from Lago’s API.

Customer current usage
3rd Node - IF conditional statement to trigger messages under conditions
This node is used to trigger the alert only when your customers overcome a threshold of usage. Those limits depend on your product and your paying features. In our present use case, we want to trigger an alert when the total consumption of usage-based features overcomes $200. You could also use thenumber of units consumed or another useful value from the payload.
- Add a new Node;
- Select IF as a new application node;
- Create a condition for the TRUE branch (when conditions are met);
- The Value is the parameter of your condition (in our case the
amount_centsof the current usage); - The Operation is the math operation you want to apply (in our case, condition is met when the total
amount_centsis larger or equal to $200);
- You can add as many conditions as you need;
- You could add an action when the condition is
FALSE.

Customer current usage with if statement
4th Node - Send an alert message to Slack
This last node is used to trigger the message. In the example, we use a Slack channel, but you could even decide to send an email directly to your customers when they pass the limits of usage.- Add a new Node;
- Select Slack as a new application node;
- Select the targeted Slack Account & Slack Channel;
- Choose the option to POST a Message; and
- Define a message and use the variables of your payload to give context to your customers about their current usage.

