# Watch a page for changes

> Create a single-page monitor with POST /v1/monitors, run a check now, read the change history, and get a signed webhook when the page changes or the monitor is disabled.

Source: https://docs.spicrawl.com/guides/monitors

Use a monitor when you want to know that a page changed without checking it yourself. Spicrawl fetches the page on a schedule, compares what it says with the last accepted version, and records each confirmed change. Point the monitor at a [webhook](https://docs.spicrawl.com/guides/webhooks.md) endpoint and you also get a signed `monitor.changed` notification when it happens. Requires an API key with the `monitors` scope. GET routes also accept `read`.

A monitor watches one page by default. A site monitor watches a whole site and reports each run as one digest; see [Watch a whole site](#watch-a-whole-site). The full reference, with every field and status code, is the [API reference](https://docs.spicrawl.com/api-reference/introduction.md).

 

## Quickstart

Four steps: register an endpoint to receive notifications, create the monitor, run one check to see it work, then read the history.

### 1. Create a webhook endpoint

```bash title="curl"
curl -X POST https://api.spicrawl.com/v1/webhooks \
  -H "Authorization: Bearer $SPICRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://hooks.example.com/spicrawl",
    "name": "page-changes",
    "events": ["monitor.changed", "monitor.failed"]
  }'
```

```python title="Python"
import os
from spicrawl import Spicrawl

with Spicrawl() as client:  # reads SPICRAWL_API_KEY
    endpoint = client.webhooks.create(
        "https://hooks.example.com/spicrawl",
        name="page-changes",
        events=["monitor.changed", "monitor.failed"],
    )
    print(endpoint["id"], endpoint["secret"])  # the secret is shown once: store it now
```

Keep the `secret` and verify each delivery with it, as the [webhooks guide](https://docs.spicrawl.com/guides/webhooks.md#verify-signatures) describes.

### 2. Create a monitor

Point it at the page and at the endpoint:

```bash title="curl"
curl -X POST https://api.spicrawl.com/v1/monitors \
  -H "Authorization: Bearer $SPICRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com/pricing",
    "name": "pricing-page",
    "interval_seconds": 3600,
    "webhook_endpoint_id": "0190f3a2-7c1e-7d4b-9a2f-3b8e5c6d7e80"
  }'
```

```python title="Python"
monitor = client.monitors.create(
    "https://example.com/pricing",
    name="pricing-page",
    interval_seconds=3600,
    webhook_endpoint_id=endpoint["id"],
)
print(monitor["id"], monitor["next_check_at"])
```

The response is `201` with the monitor. Its first scheduled check records a **baseline**: the page as it is now. A baseline is not a change, so nothing is sent for it.

### 3. Run a check now

You do not have to wait for the schedule. Run one check and read the outcome:

```bash title="curl"
curl -X POST https://api.spicrawl.com/v1/monitors/$MONITOR_ID/check \
  -H "Authorization: Bearer $SPICRAWL_API_KEY"
```

```python title="Python"
result = client.monitors.check(monitor["id"])
print(result["outcome"], result["credits"])
```

```json
{"outcome": "unchanged", "credits": 1}
```

The check returns when it is done. `outcome` is one of `unchanged`, `changed`, `not_modified` or `failed`.

### 4. Read the changes

Once the page has changed and the change is confirmed, it appears in the history, newest first:

```bash title="curl"
curl "https://api.spicrawl.com/v1/monitors/$MONITOR_ID/changes?limit=20" \
  -H "Authorization: Bearer $SPICRAWL_API_KEY"
```

```python title="Python"
for change in client.monitors.changes(monitor["id"], limit=20):
    print(change["detected_at"], change["diff"])
```

Each change has `previous_hash`, `new_hash` and a unified `diff` from the old content to the new. The page's content itself is never returned: the diff is the record of what changed.

## What is compared

By default a monitor compares the **main content** of the page, as [`/v1/scrape`](https://docs.spicrawl.com/guides/markdown.md) extracts it. Changes to the navigation, footer, ads and scripts are ignored.

To watch one part of the page, pass a CSS `selector`. The monitor compares the text of every element it matches:

```python
client.monitors.create(
    "https://example.com/status",
    selector="#status-banner",
    webhook_endpoint_id=endpoint["id"],
)
```

Before comparing, text is normalised: whitespace is collapsed, lines are trimmed and empty lines are dropped. A reflowed paragraph or a change of indentation is not a change. A changed word is.

For a page that fills itself in with JavaScript, set `js_render: true`. It costs more; see [Credits](#credits).

## Confirmed changes

Some pages flicker between two versions. `confirm_checks` says how many checks in a row must see the new version before it counts as a change:

* `1` (the default) reports the first difference.
* `2` or more waits until the next checks agree, and ignores a page that flips back.

```python
client.monitors.create(
    "https://example.com/stock",
    confirm_checks=3,
    webhook_endpoint_id=endpoint["id"],
)
```

## Schedule

`interval_seconds` is how often to check, at least your plan's minimum. It defaults to that minimum. The interval adapts within that range: it shortens after a change, and lengthens while the page stays the same. `current_interval_seconds` shows the interval in force, and `next_check_at` shows the next check.

Plan limits, the number of monitors and the minimum interval for each plan, are in the [API reference](https://docs.spicrawl.com/api-reference/introduction.md).

## Credits

Each check costs what the equivalent [`/v1/scrape`](https://docs.spicrawl.com/guides/javascript-rendering.md) call costs:

| Check             | Credits |
| ----------------- | ------- |
| Plain fetch       | 1       |
| `js_render: true` | 3       |

A failed check costs nothing. A check always fetches the page fresh and never reads from the cache.

Checks are billed to the **API key that created the monitor**. Keep that key valid. If it is revoked or expires, the monitor is disabled, and its `disabled_reason` says why.

## When a monitor is disabled

A monitor stops checking in three cases, and each one sends a `monitor.failed` event to its endpoint with the reason:

* It fails repeatedly. After 10 failed checks in a row, the monitor is disabled and a `monitor.failed` event is sent to its endpoint. `last_error` says what went wrong on the last try.
* The account runs out of credits. `disabled_reason` is `out of credits`.
* The API key that created it is revoked or expires.

Fix the cause, then turn the monitor back on. This also clears the failure count and makes the next check due now:

```bash title="curl"
curl -X PATCH https://api.spicrawl.com/v1/monitors/$MONITOR_ID \
  -H "Authorization: Bearer $SPICRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"enabled": true}'
```

```python title="Python"
client.monitors.update(monitor["id"], enabled=True)
```

## Change the monitor

Send only the fields you want to change. Any of `name`, `selector`, `interval_seconds`, `webhook_endpoint_id`, `confirm_checks`, `js_render` and `enabled`:

```python
client.monitors.update(monitor["id"], interval_seconds=86400, confirm_checks=2)
```

`webhook_endpoint_id: null` clears the endpoint, and the monitor keeps checking but sends nothing.

To stop a monitor for good and remove its history:

```python
client.monitors.delete(monitor["id"])
```

## Watch a whole site

Set `scope: "site"` to watch every page of a site. Spicrawl finds the pages from the site's sitemap, or from the links on the start page, checks them on each run, and sends one digest per run that found something.

Create it with `max_pages`, the most pages a run tracks. The cap depends on your plan: 25 on free, 250 on starter, 2,000 on pro and other paid plans, 10,000 on enterprise:

```bash title="curl"
curl -X POST https://api.spicrawl.com/v1/monitors \
  -H "Authorization: Bearer $SPICRAWL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://example.com",
    "name": "example-blog",
    "scope": "site",
    "max_pages": 250,
    "include_paths": ["/blog/*"],
    "exclude_paths": ["/blog/drafts/*"],
    "max_credits_per_run": 500,
    "interval_seconds": 86400,
    "webhook_endpoint_id": "0190f3a2-7c1e-7d4b-9a2f-3b8e5c6d7e80"
  }'
```

```python title="Python"
site = client.monitors.create(
    "https://example.com",
    name="example-blog",
    scope="site",
    max_pages=250,
    include_paths=["/blog/*"],
    exclude_paths=["/blog/drafts/*"],
    max_credits_per_run=500,
    interval_seconds=86400,
    webhook_endpoint_id=endpoint["id"],
)
```

The first run records the baseline for every page and sends nothing. Later runs report what changed.

**Which pages.** The host must match the start URL exactly, so `www.example.com` and `example.com` are different sites. `include_paths` and `exclude_paths` take up to 20 patterns each. They match the URL path. A trailing `*` matches anything below that prefix, so `/blog/*` covers `/blog/2026/post`. A page that matches `exclude_paths` is dropped even when it matches `include_paths`. The start URL is never dropped. The first `max_pages` pages in sorted order are tracked, and a page past that cap is not reported as removed. The full rules are in [the API reference](https://docs.spicrawl.com/api-reference/introduction.md).

**What it costs.** Each fetched page costs one credit, a plain scrape. Finding the pages is billed the same way: `robots.txt` and each sitemap file are scrape calls, 1 credit each when they exist. A page that the sitemap's `lastmod` shows as unchanged is not fetched and costs nothing. `max_credits_per_run` stops a run before it spends more than that, discovery included. The run is then marked `truncated`. A fetch that costs more than expected can overrun the cap by about one fetch.

**What counts as removed.** A page is removed when it answers 404 or 410. It is also removed when it disappears from the sitemaps, but only if the run read every sitemap in full. When the pages came from the start page's links, or a sitemap could not be read, a missing page is not reported as removed.

**Changing the target.** Changing `selector` or `js_render` on a site monitor starts over: the stored pages are cleared and the next run is a new baseline that sends nothing.

**List the pages.** Each tracked page has a `first_seen_at`, a `last_seen_at`, and a `removed_at` once the page is gone:

```bash title="curl"
curl "https://api.spicrawl.com/v1/monitors/$MONITOR_ID/pages?limit=100" \
  -H "Authorization: Bearer $SPICRAWL_API_KEY"
```

```python title="Python"
page = client.monitors.pages(site["id"], limit=100)
for row in page["data"]:
    print(row["url"], row["removed_at"])
if page["next_cursor"]:
    next_page = client.monitors.pages(site["id"], cursor=page["next_cursor"])
```

**Read a digest.** A run that changed something is recorded in the change history as one entry. Its `summary` holds the counts and the lists, and its `diff` is `null`:

```python title="Python"
for change in client.monitors.changes(site["id"], limit=5):
    digest = change["summary"]
    if digest is None:
        continue  # a page monitor's change
    print(change["detected_at"], digest["counts"])
    for item in digest["changed"]:
        print("changed:", item["url"])
    for url in digest["added"]:
        print("added:", url)
    for url in digest["removed"]:
        print("removed:", url)
```

The same digest arrives in the `monitor.changed` webhook. It lists at most 50 changed pages and 100 added or removed URLs, while `counts` always has the full totals. See [Receive signed webhooks](https://docs.spicrawl.com/guides/webhooks.md#site-digest-payload).

Site monitors can also be checked on demand with `POST /v1/monitors/{id}/check`. That runs the whole site and waits for it, so it can take minutes.

`max_pages`, `include_paths`, `exclude_paths` and `max_credits_per_run` can be changed with `PATCH`. `scope` cannot: to change it, create a new monitor.

## Related

* [Receive signed webhooks](https://docs.spicrawl.com/guides/webhooks.md): the endpoint that receives `monitor.changed` and `monitor.failed`
* the [API reference](https://docs.spicrawl.com/api-reference/introduction.md): every field, plan limit and status code
