# Manage webhooks from code

- Section: Webhook management (TTF API reference)
- Source: https://ttf.bot/developers/docs/#webhook-api
- The whole reference as one text: https://ttf.bot/developers/docs/llms-full.txt

Create, change and test your endpoints and rules with an API key that has webhook access.

## Make a key with webhook access

In the [dashboard](https://ttf.bot/developers/app/), tab **Overview**, panel **API keys**: type a name, open **Options** and set **Webhook access**, then press **Create key**. (No **Webhook access** field under Options? Then managing webhooks from code is not switched on yet; the dashboard does all of it meanwhile.)

| Access | What the key can do |
| --- | --- |
| `none` | Read data only. This is the default. |
| `read` | Also see your endpoints, rules and delivery logs. It never sees a signing secret. |
| `write` | Also create, change, test and delete them, and rotate secrets (includes `read`). |

> A `write` key can send your alerts to another address. Keep it on your server only, limit it to your server's IP addresses, and revoke it if it leaks. The access of a key cannot be changed later: make a new key.

Making or regenerating a key with webhook access needs a recent sign-in: the dashboard asks you to confirm it is you. Revoking a key never does.

## Your first endpoint and rule

### Create an endpoint

```bash
curl -sS -X POST 'https://api.ttf.bot/v1/webhooks/endpoints' \
  -H 'Authorization: Bearer YOUR_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
  "description": "Trading bot",
  "event_types": [
    "price",
    "wallet"
  ],
  "url": "https://bot.example.com/ttf"
}'
```

### Add a rule

```bash
curl -sS -X POST 'https://api.ttf.bot/v1/webhooks/rules' \
  -H 'Authorization: Bearer YOUR_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
  "endpoint_id": "whe_8b1f0c2d9a7e4f3b5c6d1e2a",
  "name": "PEPE breakout",
  "params": {
    "above": 1e-05,
    "chain": "eth",
    "token": "0x6982508145454ce325ddbe47a25d4ec3d2311933"
  },
  "type": "price_cross"
}'
```

### Send a test

```bash
curl -sS -X POST 'https://api.ttf.bot/v1/webhooks/endpoints/whe_8b1f0c2d9a7e4f3b5c6d1e2a/test' \
  -H 'Authorization: Bearer YOUR_KEY'
```

Take `data.endpoint.id` of the first answer for `endpoint_id` and for the test address, and keep `data.secret`: it is shown once.

## How these calls differ from data calls

- They cost **0 credits**. Your account has its own limits for them: 120 calls a minute, of which changes are at most 30 a minute and 300 a day. They never use up the dashboard's limits.
- The list of rules leaves out wallet addresses and labels (`address_count` and `label_count` say how many): get one rule to read them.
- Send the body of a change within 10 seconds, else it answers `408 request_timeout` and nothing changes.
- Times in these answers are **unix seconds**.
- Answers are never cached and carry no `ETag`.
- Call them from a server: a web page cannot send a change.
- There is no idempotency key. After a timeout on a create, list your endpoints or rules before you try again.
- `403 forbidden` naming `webhooks: read` or `webhooks: write` means the key lacks that access.
- An id that belongs to another account answers like an unknown one: `404 not_found`.
- Telegram and Discord destinations are not part of these calls: they are connected and changed in the dashboard only ([Telegram](https://ttf.bot/developers/docs/md/telegram-alerts.md), [Discord](https://ttf.bot/developers/docs/md/discord-alerts.md)). These calls list only your https endpoints and their rules, but a chat destination still takes one of your plan's endpoint slots.
