Skip to main content
Here is a typical use case of Lago and Zapier for alerting automation.

Invoice alerting example (with Zapier)

Zapier dashboard showing the Lago alerting Zap switched on

Invoice alerting flow

In this example, you build an alert that fires whenever a new invoice is emitted. This workflow uses:
  1. Lago’s webhook when a new invoice is emitted;
  2. Zapier as an automation tool, to catch, transform and send the data; and
  3. Slack as the “receiver” to alert your team anytime a new invoice is created.
Zap with three steps: catch raw hook, run JavaScript in Code by Zapier, and send a channel message in Slack

Zapier alerting flow

1. Catch a webhook when a new invoice is emitted

Lago automatically creates an invoice when a billable period is over. The invoice’s payload gives you a detailed view of what has been invoiced. The first action is to catch this invoice with a webhook:
  1. In Zapier, create a new Zap;
  2. Use the Webhooks by Zapier as the trigger of this Zap;
  3. Select the Catch Raw Hook event trigger;
  4. Copy the Zapier Webhook URL and paste it in Lago (Developers > Webhooks > Add a webhook); and
  5. Catch your first webhook when an invoice is emitted (whenever you assign an add-on or a subscription).

2. Run a script to transform the webhook

In Zapier, create a second action by clicking the + icon. This event action formats the webhook into a breakdown of fields you can use in a message.
  1. Select Code by Zapier as a new Event Action;
  2. Click on Javascript as the event code language to run;
  3. Create a field called payload. Its value is the full Raw body of the invoice object you received;
  4. Run the script (code snippet below) in the Code section;
  5. Test the action. If valid, it returns a breakdown of fields.
Code by Zapier action with the payload input field and the JavaScript that parses the invoice webhook

Script to transform the invoice payload

Zapier test output listing the invoice fields returned by the script

Breakdown of the invoice payload

3. Send a message to a Slack channel

Once you have the breakdown of fields returned by the invoice payload, use them to build a Slack message. In Zapier, create a third action by clicking the + icon. This event action sends a message to Slack with the fields of the invoice payload.
  1. Select Slack as a new app action;
  2. Select the Send Channel Message action;
  3. Choose the targeted Slack Account;
  4. Choose the targeted Slack Channel; and
  5. Create a message by using the fields returned by the payload.
Once you test and validate the entire Zap, a Slack message is sent whenever Lago emits a new invoice. You can use the same message example as detailed below:
Zapier Slack action with the target channel and the message template built from the invoice fields

Slack message template in Zapier

Slack message listing the customer, the invoice number and the amount to pay

Slack message received in the channel