# Monitor quickstart

Create a monitor, let it run, and read what changed.

## 1. Watch a search

```bash
curl https://api.millionshort.com/v1/monitors \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "query",
    "name": "bridge tenders",
    "query": "bridge inspection",
    "source": "contracts",
    "top_n": 10,
    "interval_minutes": 1440
  }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/monitors",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    json={
        "kind": "query",
        "name": "bridge tenders",
        "query": "bridge inspection",
        "source": "contracts",
        "top_n": 10,
        "interval_minutes": 1440
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/monitors', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "kind": "query",
    "name": "bridge tenders",
    "query": "bridge inspection",
    "source": "contracts",
    "top_n": 10,
    "interval_minutes": 1440
  }),
});
if (!res.ok) throw new Error(`POST /v1/monitors failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

The answer is the monitor, with its `id`. The first check records a baseline and sends nothing, unless `notify_on_create` is `true`. After that, an event is made whenever a result appears among the first `top_n` that this monitor has not seen.

## 2. Or watch a page

```bash
curl https://api.millionshort.com/v1/monitors \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "url",
    "url": "https://example.org/pricing",
    "mode": "live",
    "ignore": ["numbers", "dates"],
    "min_change_chars": 40,
    "interval_minutes": 60
  }'
```

```python
import os

import requests

r = requests.post(
    "https://api.millionshort.com/v1/monitors",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    json={
        "kind": "url",
        "url": "https://example.org/pricing",
        "mode": "live",
        "ignore": [
            "numbers",
            "dates"
        ],
        "min_change_chars": 40,
        "interval_minutes": 60
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch('https://api.millionshort.com/v1/monitors', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "kind": "url",
    "url": "https://example.org/pricing",
    "mode": "live",
    "ignore": [
      "numbers",
      "dates"
    ],
    "min_change_chars": 40,
    "interval_minutes": 60
  }),
});
if (!res.ok) throw new Error(`POST /v1/monitors failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

`ignore` and `min_change_chars` keep a counter or a date in the page from making an event every hour.

## 3. Read the events

```bash
curl "https://api.millionshort.com/v1/monitors/$MONITOR_ID/events?limit=50" \
  -H "Authorization: Bearer $MILLIONSHORT_API_KEY"
```

```python
import os

import requests

r = requests.get(
    f"https://api.millionshort.com/v1/monitors/{os.environ['MONITOR_ID']}/events?limit=50",
    headers={"Authorization": "Bearer " + os.environ["MILLIONSHORT_API_KEY"]},
    timeout=30,
)
r.raise_for_status()
print(r.json()["data"])
```

```ts
const res = await fetch(`https://api.millionshort.com/v1/monitors/${process.env.MONITOR_ID}/events?limit=50`, {
  headers: { Authorization: `Bearer ${process.env.MILLIONSHORT_API_KEY}` },
});
if (!res.ok) throw new Error(`GET /v1/monitors/…/events failed: ${res.status}`);
const { data } = (await res.json()) as { data: unknown };
console.log(data);
```

Pass the id of the last event you handled as `after` to get only newer ones. Pulling is free.

## 4. Or have them delivered

Register a [webhook](https://millionshort.com/docs/webhooks), verify it, and pass its id as `webhook_id` when you create the monitor. Events then arrive signed, and can still be pulled.

## Next

- [Parameters](https://millionshort.com/docs/monitor/parameters): every field, the shortest interval each plan and source allows, and the events.
- [Pricing and limits](https://millionshort.com/docs/monitor/pricing): what a check costs.
- [News monitoring](https://millionshort.com/docs/monitor/guides/news-monitoring): the same job with a monitor or with a scheduled search.
