# API keys and webhooks

> Create API keys for the REST API and MCP server, and send signed webhooks to your own systems when something happens on a ticket.

API keys let your own systems work with Lagotto: open tickets from your product, add messages, keep customers in step, push customer records, or connect an AI assistant without a browser. Webhooks work the other way: Lagotto tells your systems the moment something happens on a ticket. Administrators manage both, under **Settings → API keys** and **Settings → Webhooks**. Developers will find the details at [/docs/api](https://www.lagottolabs.ai/docs/api.md) and [/docs/webhooks](https://www.lagottolabs.ai/docs/webhooks.md).

## API keys

### Creating a key

1. Go to **Settings → API keys** and press **Create API key**.
2. Give it a **Name** that says where it will be used, such as Website contact form.
3. Choose its **Access**: **Read and write**, or **Read only**, which can look things up and change nothing.
4. Choose who it **Acts as**.
5. Optionally, set a date it **Expires**. Leave it empty for a key that works until it is revoked.
6. Press **Create API key**.

The token appears once, at the top of the page. Press **Copy** and store it somewhere safe: Lagotto keeps only a fingerprint of it and cannot show it again. If it is lost, revoke the key and create another.

### A key acts as a person

Every key acts as someone in your workspace. Replies and notes made with it are in that person's name, and it can never do more than they can. A **Read and write** key acting as a read-only seat can still only read. When someone is deactivated, their keys are revoked. While their address is outside your [allowed email domains](https://www.lagottolabs.ai/support/people-and-security/allowed-email-domains.md), their keys don't work.

One key works for both the REST API and the [MCP server](https://www.lagottolabs.ai/support/integrations/connecting-claude.md). Through the API, your systems open tickets, add replies, notes and customer messages, assign, route and close tickets, and manage customers and [pushed customer records](https://www.lagottolabs.ai/support/integrations/customer-data.md). Everything goes through the same steps as in the app, so routing, notifications and billing work as usual.

> **Important:** Adding a reply through the API emails the customer, just as pressing Send does.

The API answers at `https://acme.lagottolabs.ai/api/v1`, using your own workspace's address. Each key can make up to 300 API requests a minute.

### Seeing and revoking keys

The list shows each key's name, who it acts as, its access, the last characters of its token, when it was last used, and its status: **Active**, **Expires** with a date, **Expired**, **Person deactivated**, **Address not allowed** or **Revoked**.

To stop a key, press **Revoke** and confirm. Anything using it stops working straight away. Revoked keys stay on the list so you can see what they were. Creating and revoking keys is recorded in the [audit log](https://www.lagottolabs.ai/support/people-and-security/audit-log.md).

## Webhooks

### Adding an endpoint

1. Go to **Settings → Webhooks** and press **Add endpoint**.
2. Enter your **Endpoint address**. It has to be an https address on the public internet that answers with a 2xx status within 10 seconds.
3. Under **Events to send**, tick the events you want. All of them start ticked.
4. Leave **Send events to this endpoint** on, and press **Add endpoint**.

The next page shows the endpoint's **signing secret**. Copy it now: it is shown once. Your endpoint uses it to check that each request really came from Lagotto.

### Events

- `ticket.created`: a customer opened a new ticket
- `ticket.customer_replied`: a customer wrote again on a ticket
- `ticket.replied`: an agent's reply was sent to the customer
- `ticket.note_added`: somebody left an internal note
- `ticket.assigned` and `ticket.unassigned`: a ticket was given to a person, or taken off them
- `ticket.routed`: a ticket was moved to a group
- `ticket.closed` and `ticket.reopened`
- `ticket.spam_marked`: a ticket was marked as spam
- `ticket.draft_ready`: AI finished drafting a reply for an agent to review
- `ticket.pull_request_opened` and `ticket.pull_request_merged`: a fix's pull request was opened or merged. See [Fixes and pull requests from GitHub](https://www.lagottolabs.ai/support/integrations/github-fixes.md)
- `csat.received`: a customer rated how their ticket was handled

The text of an internal note is sent only with `ticket.note_added`, so leave that event unticked if notes should not leave Lagotto.

### Checking deliveries

Press **Deliveries** beside an endpoint to see what was sent in the last 30 days: each event, its status (**Queued**, **Retrying**, **Delivered** or **Failed**), your endpoint's response, and how many attempts it took. Open an event to see exactly what was sent.

Press **Send test event** to send a test right away. It is tried once and does not count as a failure.

### Retries and switching off

- A delivery that does not get a 2xx answer is tried again, with longer waits each time, up to 8 attempts over about a day. Redirects are not followed.
- After 20 deliveries in a row have failed, Lagotto stops calling the endpoint. It shows **Switched off after failures**, and the workspace's administrators get an email.
- Once your endpoint is answering again, open it, switch **Send events to this endpoint** back on and press **Save**. Events from while it was off are not sent again.

### Changing or deleting an endpoint

Press **Edit** beside an endpoint to change its address or events, or switch it off.

If the secret is lost or may have leaked, press **Rotate secret**. The new one is shown once, and the old one stops working straight away, so update your endpoint at the same time.

To remove an endpoint and its delivery log, press **Delete endpoint** on its edit page.
