# Acting on incidents and scans

Besides reading, the API can do three things you do by hand in the console: acknowledge an incident, resolve an incident and run a scan of a domain now. A key can do them only with the `incidents.edit` or `domains.edit` scope, and only while its owner’s role holds the same permission (a service account’s: its roles); see [authentication and keys](https://developer.watchtower15.com/api/authentication/).

Each call is a `POST` with no body. The organisation is the key’s, never a parameter. A write counts in the same [rate limits](https://developer.watchtower15.com/api/rate-limits/) as a read, and appears in the [audit trail](https://docs.watchtower15.com/platform/audit-trail/) with the key that made it.

| Call | Scope | Answers |
| --- | --- | --- |
| `POST /v1/incidents/{incident_uuid}/acknowledge` | `incidents.edit` | `200`, the incident |
| `POST /v1/incidents/{incident_uuid}/resolve` | `incidents.edit` | `200`, the incident and its `resolution` |
| `POST /v1/domains/{domain_uuid}/scans/{scan_type}` | `domains.edit` | `202`, the queued scan |
| `GET /v1/scans/{scan_uuid}` | `domains.view` | `200`, the scan’s progress |

An uuid that does not exist, or belongs to another organisation, answers `404` `not_found`: the two cannot be told apart. A scope or permission the key lacks answers `403` `forbidden`.

## Acknowledge and resolve an incident

```plaintext
curl -X POST -H "Authorization: Bearer $WT15_API_KEY" \
  https://rest.watchtower15.com/v1/incidents/$INCIDENT_UUID/acknowledge
```

Both calls do what the console’s buttons do, including the notifications they send, which name the member the key acts as. They answer the incident after the call:

```json
{
  "data": {
    "uuid": "…",
    "status": "acknowledged",
    "changed": true,
    "acknowledged_at": 1793000000000,
    "acknowledged_by": { "name": "…" }
  }
}
```

-   **`changed`** says whether this call did anything. An incident that is already acknowledged or resolved answers `200` with `changed` `false` and is left as it was, so a script can call again safely.
-   **Resolve** answers `resolved_at`, `resolved_by` and `resolution`. `resolution` is `null` when `changed` is `false`. Otherwise it is `checked_again`, which means the next alarm pass opens a new incident if the condition still holds, or `accepted`, which means WatchTower15 accepted the change (a closed port, a stopped service) and the alarm returns only when the port or service comes back and stops again.

## Run a scan now

```plaintext
curl -X POST -H "Authorization: Bearer $WT15_API_KEY" \
  https://rest.watchtower15.com/v1/domains/$DOMAIN_UUID/scans/ssl
```

`scan_type` is `dns`, `expiry`, `information` (WHOIS) or `ssl`, on any domain of the organisation, as the console’s **Trigger a scan now** accepts them. The call queues the scan and answers at once with `202`:

```json
{
  "data": {
    "scan_uuid": "…",
    "scan_type": "ssl",
    "status": "queued",
    "queued_at": 1793000000000,
    "domain_uuid": "…"
  }
}
```

### Follow the scan

`GET /v1/scans/{scan_uuid}` answers the scan’s progress until it ends:

-   `uuid`, `scan_type` and `domain_uuid`;
-   `status`: `queued`, `running`, `completed`, `failed` or `timeout`. The set is open, so a script treats a value it does not know as “not finished yet”;
-   `outcome`: what a finished scan found, for example `data_found` or `no_data`; `null` until it ends;
-   `queued_at`, `started_at`, `completed_at` and `execution_time_ms`;
-   `error_message`: why a scan failed, as the console shows it.

It does not return what the scan found. The findings of a DNS, expiry or SSL scan are on `GET /v1/domains/{domain_uuid}/scans`; the findings of a WHOIS (`information`) scan, which hold registrant data, stay in the console.

### The cooldown

A scan costs money and load, so a domain can be scanned at most **once every 10 minutes for each scan type**. A second call inside that time answers `429` `rate_limited` with `Retry-After`, the seconds left, and starts nothing:

```json
{ "type": "…/api/errors/rate_limited/", "status": 429, "code": "rate_limited",
  "detail": "This domain's SSL certificate scan was started less than 10 minutes ago. Retry after 412 s." }
```

Back off for `Retry-After` seconds; do not retry at once. It holds for every key and every caller of the API, and also after a `500` from this call: the scan may have been queued, so a script waits for the next answer’s `Retry-After` instead of calling again.

### Billing

A scan is billed as it is in the console. When the organisation has no payment method, or an invoice is overdue, the call answers `402` `payment_required` or `invoice_overdue`: nothing is billed and no cooldown starts, so the call can be repeated once the billing is settled.

## Retrying a write safely

Each of the three writes takes an optional **`Idempotency-Key`** header, so a script that timed out, or got a `500`, can send the same call again without doing it twice:

```plaintext
curl -X POST -H "Authorization: Bearer $WT15_API_KEY" \
  -H "Idempotency-Key: nightly-scan-42" \
  https://rest.watchtower15.com/v1/domains/$DOMAIN_UUID/scans/ssl
```

A key is 1 to 255 visible ASCII characters (no spaces). Pick one for each thing you want done, and send the same one on every retry of it.

-   **A repeat of the same request within 24 hours** returns the **first answer**, with the same body, and the header `Idempotent-Replayed: true`. Nothing runs again: no scan is queued or billed, and no cooldown is asked. A retried acknowledge reads `changed` `true` as the first call did, where a call without a key would read `false`. A replay counts as a call in your [rate limits](https://developer.watchtower15.com/api/rate-limits/).
-   **The same key on a different request** (another incident, another domain, another scan type) is refused `422` `invalid_request`, with `errors` naming the `Idempotency-Key` header, and nothing runs. See [invalid request](https://developer.watchtower15.com/api/errors/invalid_request/).
-   **A key outside 1 to 255 visible ASCII characters** is refused the same way. A header of only spaces counts as no key.
-   **Only a successful answer is kept.** A call that was refused (`402`, `404`, `422` or the scan cooldown’s `429`) keeps no key and starts no cooldown, so the same key runs again once the cause is gone.
-   **Keys are per API key.** Two keys, or two members’ scripts, never collide.
-   **Without a key** nothing changes: the call behaves as described above.

### How a key meets the scan cooldown

| Call | Answer |
| --- | --- |
| The first call with a key | As above: `202` and a `scan_uuid`. |
| The same key again within 24 hours, same domain and scan type | The first `202`, the same `scan_uuid`, `Idempotent-Replayed: true`. The cooldown is not asked. |
| The same key on another domain or scan type | `422` `invalid_request`. Nothing runs. |
| A new key within 10 minutes of the scan | The cooldown’s `429` `rate_limited` with `Retry-After`. The new key is not kept. |

**After a timeout or a `500` on a keyed scan, retry with the same key.** If the first call got as far as queueing the scan, the retry answers with its `scan_uuid`, and the script can follow it with `GET /v1/scans/{scan_uuid}`. A scan whose message could not be sent ends `failed` on its own after a while, so poll it, and start a new one with a new key only once the cooldown has passed.

Source: https://developer.watchtower15.com/api/acting-on-incidents-and-scans/
