# Create an endpoint

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

`POST /v1/webhooks/endpoints`

- Base URL: `https://api.ttf.bot`
- Cost: Free
- Plan: Free
- API key: required. Send `Authorization: Bearer YOUR_KEY` (or `X-API-Key: YOUR_KEY`).
- A refused or failed call costs nothing.
- Key needs: webhooks: write

Register the https URL TTF should POST to. Do it from your own deploy script and store the signing secret it returns.

- Store `data.secret` at once: no other call returns it. Then [check the signature](https://ttf.bot/developers/docs/md/webhook-signatures.md) of every delivery.

## Exact rules

The signing secret is in this answer only. A URL is unique per account: creating it again answers 409 duplicate_url. Needs an API key with `webhooks: write`. Costs 0 credits; counted in your account's webhook change and read limits.

## Parameters

No parameters: just send it.

## Request body

`application/json`, required.

- `url` (string, required): Public https URL (port 443 or 8443, a host name that resolves, no user name or password).
- `description` (string, optional): A note, up to 120 characters. At most 120 characters.
- `enabled` (boolean, optional): false = create it paused (default true).
- `event_types` (array of strings, optional): Event types to receive (default: all). One of: `price`, `trending`, `wallet`, `signal`.

Example body:

```json
{
  "description": "Trading bot",
  "event_types": [
    "price",
    "wallet"
  ],
  "url": "https://bot.example.com/ttf"
}
```

Another example body (`all_events`): Every event type: only the URL.

```json
{
  "url": "https://bot.example.com/ttf"
}
```

## Example request

```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"
}'
```

Put your key in place of `YOUR_KEY`.

## Example answer

`201` (`default`): Create an endpoint

```json
{
  "data": {
    "endpoint": {
      "created": 1795000000,
      "description": "Trading bot",
      "enabled": true,
      "event_types": [
        "price",
        "trending",
        "wallet",
        "signal"
      ],
      "id": "whe_8b1f0c2d9a7e4f3b5c6d1e2a",
      "over_limit": false,
      "secret_version": 1,
      "status": "active",
      "updated": 1795000000,
      "url": "https://bot.example.com/ttf"
    },
    "notice": "Copy this signing secret now: it is shown only once. Verify each delivery with it (HMAC-SHA256 of \"<timestamp>.<body>\").",
    "secret": "whsec_EXAMPLE"
  },
  "meta": {
    "cost": 0,
    "request_id": "3f2a9c0e5b7d4e18a6c1f0b2d9e8a7c6"
  }
}
```

## Response fields

`always` = in every answer; `always*` = in every answer that does not narrow it with `fields`; any other field is left out when there is no value (never `null`). Objects are open: ignore keys you do not know.

A `201` answer is `{"data", "meta"}` (`HookEndpointCreatedAnswer`).

### `data`

- `endpoint` (object, always): A webhook endpoint: where deliveries go. Its signing secret is never part of it.
  - `created` (integer, always): When it was created. Unix time in SECONDS.
  - `description` (string, always): Your note (empty text when none).
  - `enabled` (boolean, always): true = switched on.
  - `event_types` (array of strings, always): The event types it receives. One of: `price`, `trending`, `wallet`, `signal`.
  - `id` (string, always): Endpoint id (whe_ + 24 hex).
  - `over_limit` (boolean, always): true = above the number of endpoints of your plan, so it gets nothing.
  - `secret_version` (integer, always): How many signing secrets this endpoint has had (1 = never rotated).
  - `status` (string, always): active = receiving; failing = receiving, recent deliveries failed; paused = switched off by you; disabled = switched off by TTF after repeated failures; paused_over_limit = above your plan. Known values: `active`, `paused`, `failing`, `disabled`, `paused_over_limit` (more may come: handle unknown ones).
  - `updated` (integer, always): When it was last changed. Unix time in SECONDS.
  - `url` (string, always): Where deliveries are POSTed.
  - `previous_secret_until` (integer): After a rotation: when the previous secret stops signing. Absent otherwise. Unix time in SECONDS.
- `notice` (string, always): What to do with the secret, in words.
- `secret` (string, always): The signing secret (whsec_...). It is in this answer ONLY: store it now.

### `meta`

- `cost` (integer, always): Credits this call finally spent (= the X-Credits-Cost header). 0 for free routes and refused calls.
- `request_id` (string, always): Id of this request (= the X-Request-Id header). Quote it to support.
- `cached` (array of strings): The groups answered from the shared answer cache (charged at their cached weight). Absent when none.
- `partial` (array of strings): Something is missing. A bare group name ("holders"): that group failed, its entry in data is {"error": {...}} and only the attempt fee can apply. A dotted "\<group>.\<part>" ("security.holders"): a part of a group that DID answer is missing (see its complete / missing); that group is still billed. Absent when nothing is missing.

## Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `bad_request` | Bad request: an unknown field or a bad value. Nothing changed. Codes: bad_request. |
| 401 | `unauthorized` | The API key is missing or not valid. Codes: unauthorized. |
| 402 | `payment_required` | The subscription of this API key has ended. Codes: payment_required. |
| 403 | `forbidden` `quota_exceeded` `account_suspended` | The key lacks the webhook permission (or its plan, IP or account refuses the call), or a plan limit is reached. Codes: forbidden, quota_exceeded, account_suspended. |
| 404 | `not_found` | No such endpoint or rule in your account, or the webhook API is switched off. Codes: not_found. |
| 405 | `method_not_allowed` | Wrong HTTP method for this route. Codes: method_not_allowed. |
| 408 | `request_timeout` | The request body did not arrive in time. Nothing changed. Codes: request_timeout. |
| 409 | `duplicate_url` | The change conflicts with the current state. Nothing changed. Codes: duplicate_url. |
| 413 | `too_large` | The body is too large. Codes: too_large. |
| 415 | `unsupported_media_type` | The body is not declared as JSON. Codes: unsupported_media_type. |
| 422 | `url_not_allowed` | The URL or the rule was refused. Nothing changed. Codes: url_not_allowed. |
| 429 | `rate_limited` | Too many requests, or too many webhook reads or changes of your account. See Retry-After. Codes: rate_limited. |
| 500 | `internal` | Unexpected error. Codes: internal. |
| 503 | `unavailable` `not_configured` | The service cannot answer right now. See Retry-After. Codes: unavailable, not_configured. |
| other | `error` | Any other refusal of the HTTP layer (rare): the status says which. Codes: error. |

Every error is `{"error": {"code", "message", "doc_url", "request_id"}}`. What each code means and how to fix it: [Errors](https://ttf.bot/developers/docs/md/errors.md).
