# Change a monitor

> Send only the fields to change: `name`, `selector`, `interval_seconds`, `webhook_endpoint_id`, `confirm_checks`, `js_render` or `enabled`.

Source: https://docs.spicrawl.com/api-reference/monitors/monitors-update

## PATCH /v1/monitors/{monitorID}

Operation ID: `monitorsUpdate`. API key scope: `monitors`.

Send only the fields to change: `name`, `selector`, `interval_seconds`, `webhook_endpoint_id`,
`confirm_checks`, `js_render` or `enabled`. Any other field is a 400.

A disabled monitor stays disabled until you send `enabled: true`. That also clears `disabled_reason` and
`last_error`, resets `consecutive_failures` to 0, and makes the next check due now. Re-enable only once the
cause is fixed: the page is back, or the key and credits are good again.

### Example

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

### Parameters

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `monitorID` | path | string | yes | The monitor `id` returned by `POST /v1/monitors`. An id of another organization answers 404. |

### Request body

`application/json`, required.

| Field | Type | Required | Description |
|---|---|---|---|
| `name` | string | no |  |
| `selector` | string \| null | no |  |
| `interval_seconds` | integer | no |  |
| `webhook_endpoint_id` | string \| null | no | Null clears the endpoint. |
| `confirm_checks` | integer | no |  |
| `js_render` | boolean | no |  |
| `enabled` | boolean | no | True re-enables the monitor: it clears `disabled_reason` and `last_error`, resets `consecutive_failures` to 0, and sets `next_check_at` to now. |
| `max_pages` | integer | no | Site monitors only. Same rule as on create, capped by the plan. |
| `include_paths` | array of string | no | Site monitors only. Replaces the whole list. |
| `exclude_paths` | array of string | no | Site monitors only. Replaces the whole list. |
| `max_credits_per_run` | integer \| null | no | Site monitors only. Null removes the cap. |

Example `reenable`: Re-enable after the page came back

```json
{
  "enabled": true
}
```

Example `slower`: Check once a day

```json
{
  "interval_seconds": 86400
}
```

### Responses

#### 200

The monitor after the change.

Headers: `X-Request-Id`.

`application/json`.

| Field | Type | Required | Description |
|---|---|---|---|
| `id` | string | yes |  |
| `name` | string | yes | Defaults to the host of `url`. |
| `url` | string (uri) | yes |  |
| `selector` | string \| null | yes | CSS selector. Every element it matches is watched, as its text, in document order. Null watches the main content of the page. |
| `js_render` | boolean | yes | Render the page in a browser before reading it. Costs more credits; see the Monitors section of the API reference. |
| `interval_seconds` | integer | yes | The interval you asked for. Defaults to the plan minimum. |
| `current_interval_seconds` | integer | yes | The interval in force now. It moves between the plan minimum and `interval_seconds` as the page changes or stays put. |
| `confirm_checks` | integer | yes | A change must be seen on this many checks in a row before it is reported. 1 reports the first change. |
| `webhook_endpoint_id` | string \| null | yes | The endpoint that receives `monitor.changed` and `monitor.failed`. Null when none is set. |
| `enabled` | boolean | yes | False once the monitor was disabled, by repeated failures, by running out of credits, or by `enabled: false`. |
| `disabled_reason` | string \| null | yes | Why the monitor is disabled, when it is. Null while enabled. |
| `last_error` | string \| null | yes | A short description of the most recent failed check. Cleared by a successful check and by re-enabling. |
| `last_checked_at` | string \| null (date-time) | yes |  |
| `last_changed_at` | string \| null (date-time) | yes |  |
| `next_check_at` | string \| null (date-time) | yes |  |
| `consecutive_failures` | integer | yes | Failed checks in a row. A success resets it. The monitor disables itself when it reaches the limit. |
| `created_at` | string (date-time) | yes |  |
| `updated_at` | string (date-time) | yes |  |
| `scope` | string: `page`, `site` | yes | `page` watches one URL. `site` watches every page the start URL leads to on its exact host. Set at create; it cannot be changed. |
| `max_pages` | integer \| null | yes | Site monitors only. The most pages a run considers. Null for page monitors. |
| `include_paths` | array of string | yes | Site monitors only. Path patterns a page must match to be kept. Empty keeps every path. |
| `exclude_paths` | array of string | yes | Site monitors only. Path patterns that drop a page. A page that matches one is dropped even when it matches `include_paths`. The start URL is exempt from both lists. |
| `max_credits_per_run` | integer \| null | yes | Site monitors only. A run stops fetching when the next fetch would exceed this many credits, discovery included. A fetch that costs more than expected can overrun it by about one fetch. Null for no cap. |
| `pages_tracked` | integer \| null | yes | Site monitors only. Pages the monitor currently tracks, not counting removed ones. Null for page monitors. |
| `last_run` |  | yes | Site monitors only. Counts of the most recent run. Null until a run has finished, and for page monitors. |

#### 400

The request is invalid. Not retryable; fix the request using `code` and `diagnostics.hint`.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

#### 401

Missing, invalid, revoked or expired key. Not retryable with the same key.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

#### 403

The key lacks the scope this route requires (`ERR::AUTH::INSUFFICIENT_SCOPE`), or the action is not permitted.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

#### 404

No such resource for this key's organization.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

#### 500

Internal error. Retryable when `retryable` is true.

Headers: `X-Request-Id`.

`application/problem+json` (`Problem` schema).

Full OpenAPI spec: https://docs.spicrawl.com/openapi.yaml
