> ## Documentation Index
> Fetch the complete documentation index at: https://getlago.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Zapier

> Build an invoice alert with Zapier that catches Lago's invoice webhook, parses it with a script and posts the invoice details to a Slack channel.

Zapier is a no-code automation tool that can catch Lago webhooks and forward them to other apps. Use it to alert your team in Slack whenever Lago issues an invoice.

## Invoice alerting example (with Zapier)

![Zapier dashboard showing the Lago alerting Zap switched on](https://mintcdn.com/lago-docs/ugh-mbZn6BFsC-Za/integrations/alerting/images/invoice-alerting-flow-6c86d0faab38b7740a20925797099c70.png?fit=max\&auto=format\&n=ugh-mbZn6BFsC-Za\&q=85\&s=2292b4e46ab092c55ac33931ddcb2e9d)

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.
3. Slack as the receiver, to alert your team when 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](https://mintcdn.com/lago-docs/ugh-mbZn6BFsC-Za/integrations/alerting/images/zapier-flow-invoice-alerting-6916f7acabd57ddc10125d0fe1b9f7e1.png?fit=max\&auto=format\&n=ugh-mbZn6BFsC-Za\&q=85\&s=a69497e86c4674d4d766d15c26b74344)

Zapier alerting flow

> [!NOTE]
>
> The API lists the webhook event types (including `invoice.created`) but does not document webhook payloads yet. The fields below come from the invoice webhook. Check the payload you receive and confirm field names with the Lago team before you rely on them.

## 1. Catch a webhook when a new invoice is emitted

Lago creates an invoice when a contract's billing period closes. The invoice payload gives a detailed view of what was invoiced. The first action is to catch it with a webhook:

1. In Zapier, create a new Zap.
2. Use **Webhooks by Zapier** as the trigger of this Zap.
3. Select the **Catch Raw Hook** event trigger.
4. Copy the Zapier webhook URL and register it as a [webhook endpoint](https://getlago.com/docs/v2/guide/webhooks.md) in Lago (**Developers** > **Webhooks** > **Add a webhook**, or [`POST /api/v2/webhook_endpoints`](https://getlago.com/docs/v2/api-reference/webhook-endpoints/create)).
5. Catch your first webhook when an invoice is emitted.

## 2. Run a script to transform the webhook

In Zapier, create a second action by clicking the `+` icon. This action formats the webhook into fields you can use in a message.

1. Select **Code by Zapier** as a new *Event Action*.
2. Click **Javascript** as the code language.
3. Create a field called `payload`. Its value is the full **Raw body** of the webhook you received.
4. Run the script below in the **Code** section.
5. Test the action. If valid, it returns a breakdown of fields.

```javascript theme={"dark"}
var obj = JSON.parse(inputData.payload);

if(obj.object_type == "invoice"){
  return obj
}
```

![Code by Zapier action with the payload input field and the JavaScript that parses the invoice webhook](https://mintcdn.com/lago-docs/ugh-mbZn6BFsC-Za/integrations/alerting/images/script-invoice-alerting-ad7c8393f51e76b0601c2e153b1ee1dc.png?fit=max\&auto=format\&n=ugh-mbZn6BFsC-Za\&q=85\&s=c5cb0c77f8d0a9ffc70fb8f7a7bba54b)

Script to transform the invoice payload

## 3. Send a message to a Slack channel

Use the fields returned by the script to build a Slack message.

In Zapier, create a third action by clicking the `+` icon.

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**.
5. Create a message with the fields returned by the payload.

Once you test and validate the Zap, a Slack message is sent whenever Lago emits a new invoice.

![Zapier Slack action with the target channel and the message template built from the invoice fields](https://mintcdn.com/lago-docs/ugh-mbZn6BFsC-Za/integrations/alerting/images/slack-message-example-228799226dec5760962b69c5e7816daf.png?fit=max\&auto=format\&n=ugh-mbZn6BFsC-Za\&q=85\&s=83344caf2ba61cf3d4bc493f2a884a42)

Slack message template in Zapier

![Slack message listing the customer, the invoice number and the amount to pay](https://mintcdn.com/lago-docs/ugh-mbZn6BFsC-Za/integrations/alerting/images/slack-test-message-alerting-f3d6a83c9a3468528ebc31d9e57c1a47.png?fit=max\&auto=format\&n=ugh-mbZn6BFsC-Za\&q=85\&s=9c5819bd2c6843587f1509d0a35b1301)

Slack message received in the channel

> [card] [Webhooks](https://getlago.com/docs/v2/guide/webhooks.md)
>
> Register and manage webhook endpoints.

> [card] [Create a webhook endpoint](https://getlago.com/docs/v2/api-reference/webhook-endpoints/create.md)
>
> `POST /api/v2/webhook_endpoints` reference.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.