# POST /v2/scan/subscribe

**Subscribe to a scan query**

Subscribes to a free-form `q` (same grammar as `POST /v2/scan`). The webhook delivers the match set every time it changes (tickers entering or leaving). Optionally scope to a `universe`. Max `q` length is 1500 chars. Response includes a `test_url` — subscribing does NOT auto-fire anything at your endpoint; call it to send a real-shape `webhook.fired` POST instantly and validate your receiver.

Custom signals referenced in `q` are expanded and frozen into the webhook at creation — editing the signal later will not change this subscription (re-subscribe to apply). See Create a custom signal.

## Plan access

- **Plan access.** Paid plans (Hobby and above).
- **Cadence.** Real-time on every paid plan — evaluated on every data refresh (~1×/min), so a match is delivered within seconds of it landing. Optionally throttle a webhook to hourly or at-market-open.
- **Capacity.** Hobby 10 · Pro 100 · Scale & Enterprise unlimited.

## Body parameters

| Name | In | Type | Required | Description |
|------|----|----|----------|-------------|
| `q` | body | string | yes | WHERE-clause expression using signal/column names. Max 1500 chars. Example: `gap_up AND small_cap AND high_volume_alert`. |
| `universe` | body | string | no | System or user-owned universe to scope the scan (e.g. `top_100`). |
| `target_url` | body | string | no | https:// URL to POST when the match set changes. Omit for in-app delivery. |
| `channel` | body | string | no | Delivery channel. `webhook` (POST to `target_url`), `discord` (post an embed to `discord_url`), `in_app` (dashboard only), or `mobile_push` (notify a phone signed in to the Tickerbot mobile app; requires a `device_id` from `POST /v2/devices/register`). Inferred when omitted: `webhook` if `target_url` is set, `discord` if `discord_url` is set, else `in_app`. `slack` is reserved and returns `501`. See the Delivery channels guide. Enum: `webhook`, `discord`, `in_app`, `mobile_push`. |
| `discord_url` | body | string | no | Discord incoming-webhook URL (`https://discord.com/api/webhooks/…`). Required when `channel` is `discord`. Stored as a posting credential and stripped from list/get responses, which set `channel_config_present: true` instead. |
| `cadence` | body | string | no | `realtime` (the default) is evaluated on every data refresh (~1×/min); `hourly` and `nyse_open` throttle to a batch schedule. `1m` is a deprecated alias for `realtime`. Enum: `realtime`, `hourly`, `nyse_open`. |
| `name` | body | string | no | Human-readable label (up to 80 chars). Defaults to `scan: <q>`. |
| `fields` | body | string | no | Comma-separated extra columns to include in each fired payload match row, beyond the standard set (`ticker`, `name`, `asset_type`, `price`, `day_change_pct`, `market_cap`). Each must be a real column; an unknown column is rejected at creation. Example: `rsi_14,macd_line`. |

## Status codes

- **200** — Webhook subscription created.
- **400** — `bad_request` or `invalid_query` — missing/malformed `q`, or invalid `target_url`/`cadence`.
- **403** — `webhook_tier_required` or `webhook_limit_reached`.

## Sample response

```json
{
  "id": "wh_eW9rTq-c52v",
  "name": "scan: gap_up AND small_cap AND high_volume_alert",
  "q": "gap_up AND small_cap AND high_volume_alert",
  "cadence": "realtime",
  "target_url": "https://example.com/hook",
  "delivery": "webhook",
  "status": "active",
  "subscription_origin": { "type": "scan", "ref": "q", "condition": null },
  "test_url": "/v2/webhooks/wh_eW9rTq-c52v/test",
  "created_at": 1737580800
}
```

## Examples

### Subscribe to a free-form scan

Request:

```shell
curl -X POST "https://api.tickerbot.io/v2/scan/subscribe" \
  -H "Authorization: Bearer YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"q":"gap_up AND small_cap AND high_volume_alert","target_url":"https://example.com/hook","cadence":"realtime"}'
```

Response (`200`):

```json
{
  "id": "wh_eW9rTq-c52v",
  "name": "scan: gap_up AND small_cap AND high_volume_alert",
  "q": "gap_up AND small_cap AND high_volume_alert",
  "cadence": "realtime",
  "target_url": "https://example.com/hook",
  "delivery": "webhook",
  "status": "active",
  "subscription_origin": { "type": "scan", "ref": "q", "condition": null },
  "test_url": "/v2/webhooks/wh_eW9rTq-c52v/test",
  "created_at": 1737580800
}
```

---

Interactive sandbox + parameter editor: https://tickerbot.io/docs/endpoints/scan/subscribe
