Overconsumption alerting example (with n8n)
When a customer overconsumes during a period, you might need to warn them. This happens with cloud or API products. Automatic billing should not leave your customers with a bad surprise when they open their invoices. Here is a full workflow to create an alerting system based on your customers’ current usage, using n8n, an 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 an IF statement to condition the trigger (here, 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. This example uses Slack.
1st node - CRON expression to repeat tasks at a defined interval
The first node triggers the automation automatically at a defined interval.- Add a new Node;
- Select CRON as a new application node;
- Set the Mode to
Every X; and - Set the Value to
10and the Unit toMinutes.

Cron expression
2nd node - Catch customers’ current usage with an HTTP request
This node fetches current usage from the Lago API with an HTTP request.- Add a new Node;
- Select HTTP Request as a new application node;
- Fetch customers’ current usage from Lago API, with
external_subscription_idas a query parameter; - Set the
Authorizationheader toBearer __YOUR_API_KEY__and theContent-Typeheader toapplication/json; and - Execute the node to fetch the payload from the Lago API.
customer_usage object, so the next node reads its fields with the customer_usage prefix.

Customer current usage
3rd node - IF conditional statement to trigger messages under conditions
This node triggers the alert only when your customers exceed a usage threshold. Those limits depend on your product and your paid features. In this example, the alert fires when the total consumption of usage-based features goes over $200. You could also use theunits of a charge 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);
- Value 1 is the parameter of your condition, here
customer_usage.total_amount_cents; - Operation is the comparison you want to apply. Select
Larger or Equaland set Value 2 to20000:total_amount_centsis expressed in cents, so a $200 threshold is20000.
FALSE branch.

Customer current usage with if statement
4th node - Send an alert message to Slack
This last node sends the message. This example uses a Slack channel, but you could also send an email directly to your customers when they pass their usage limits.- 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.

