# Changing resources

This page lists what version 1 creates, changes and deletes, and is the contract every one of those writes follows. Each operation is in the [reference](https://developer.watchtower15.com/api/reference/) with its body and its answers; the rules below hold for all of them. Besides the three first writes, which [acknowledge an incident, resolve an incident and run a domain scan](https://developer.watchtower15.com/api/acting-on-incidents-and-scans/), version 1 changes servers and their ports and volumes, and creates, updates and deletes server profiles, domains, services, databases, custom metrics, metric sources, log sources, tags and tag groups, creates, updates and deletes alarm channels, alarm policies and alarms, manages server profiles’ alarm templates, and runs the actions the console has on them.

A write is a `POST`, a `PUT` or a `DELETE`. A `PATCH` is refused everywhere.

## What version 1 changes

Every operation below takes the key’s organisation, never a parameter. The scope is the one the key needs, besides the permission your role holds; a service account’s key, besides the permission its roles grant.

### Tags

| Operation | Call | Scope |
| --- | --- | --- |
| `tags.create` | `POST /v1/tags` | `tags.edit` |
| `tags.update` | `PUT /v1/tags/{tag_uuid}` | `tags.edit` |
| `tags.delete` | `DELETE /v1/tags/{tag_uuid}` | `tags.delete` |

### Tag groups

| Operation | Call | Scope |
| --- | --- | --- |
| `tagGroups.create` | `POST /v1/tag-groups` | `tags.edit` |
| `tagGroups.update` | `PUT /v1/tag-groups/{tag_group_uuid}` | `tags.edit` |
| `tagGroups.delete` | `DELETE /v1/tag-groups/{tag_group_uuid}` | `tags.delete` |

### Servers

| Operation | Call | Scope |
| --- | --- | --- |
| `servers.update` | `PUT /v1/servers/{server_uuid}` | `servers.edit` |
| `servers.delete` | `DELETE /v1/servers/{server_uuid}` | `servers.delete` |
| `servers.approve` | `POST /v1/servers/{server_uuid}/approve` | `servers.edit` |
| `servers.archive` | `POST /v1/servers/{server_uuid}/archive` | `servers.edit` |
| `servers.reactivate` | `POST /v1/servers/{server_uuid}/reactivate` | `servers.edit` |
| `servers.provision` (deprecated, refused) | `POST /v1/servers/{server_uuid}/provision` | `servers.edit` |
| `servers.revoke` | `POST /v1/servers/{server_uuid}/revoke` | `servers.delete` |
| `servers.rotateToken` (deprecated, refused) | `POST /v1/servers/{server_uuid}/rotate-token` | `servers.edit` |
| `servers.updatePort` | `PUT /v1/servers/{server_uuid}/ports/{port_uuid}` | `servers.edit` |
| `servers.forgetPort` | `POST /v1/servers/{server_uuid}/ports/{port_uuid}/forget` | `servers.edit` |
| `servers.updateVolume` | `PUT /v1/servers/{server_uuid}/volumes/{volume_uuid}` | `servers.edit` |
| `servers.dismissSecurityFinding` | `POST /v1/servers/{server_uuid}/security-findings/{finding_uuid}/dismiss` | `security.edit` |
| `servers.restoreSecurityFinding` | `POST /v1/servers/{server_uuid}/security-findings/{finding_uuid}/restore` | `security.edit` |
| `servers.recheckPosture` | `POST /v1/servers/{server_uuid}/security-posture/recheck` | `security.edit` |
| `servers.recheckOsUpdates` | `POST /v1/servers/{server_uuid}/os-updates/recheck` | `security.edit` |

A server’s security findings list holds three kinds: vulnerabilities, posture checks and compromise indicators (`kind=indicator`); dismiss and restore take a finding of any of the three. A finding of another kind (a service to restart) is not listed, and its uuid answers `404`.

### Server profiles

| Operation | Call | Scope |
| --- | --- | --- |
| `serverProfiles.create` | `POST /v1/server-profiles` | `server_profiles.edit` |
| `serverProfiles.update` | `PUT /v1/server-profiles/{server_profile_uuid}` | `server_profiles.edit` |
| `serverProfiles.duplicate` | `POST /v1/server-profiles/{server_profile_uuid}/duplicate` | `server_profiles.edit` |
| `serverProfiles.delete` | `DELETE /v1/server-profiles/{server_profile_uuid}` | `server_profiles.delete` |

### Domains

| Operation | Call | Scope |
| --- | --- | --- |
| `domains.runScan` | `POST /v1/domains/{domain_uuid}/scans/{scan_type}` | `domains.edit` |
| `domains.create` | `POST /v1/domains` | `domains.edit` |
| `domains.update` | `PUT /v1/domains/{domain_uuid}` | `domains.edit` |
| `domains.delete` | `DELETE /v1/domains/{domain_uuid}` | `domains.delete` |
| `domains.startVerification` | `POST /v1/domains/{domain_uuid}/verification` | `domains.view` |
| `domains.checkVerification` | `POST /v1/domains/{domain_uuid}/verification/check` | `domains.view` |

### Services

| Operation | Call | Scope |
| --- | --- | --- |
| `services.create` | `POST /v1/services` | `services.edit` |
| `services.update` | `PUT /v1/services/{service_uuid}` | `services.edit` |
| `services.delete` | `DELETE /v1/services/{service_uuid}` | `services.delete` |
| `services.collectorPreview` | `POST /v1/services/collector-preview` | `services.edit` |
| `services.verify` | `POST /v1/services/{service_uuid}/verify` | `services.edit` |
| `services.reassign` | `POST /v1/services/{service_uuid}/reassign` | `services.edit` |
| `services.pause` | `POST /v1/services/{service_uuid}/pause` | `services.edit` |
| `services.resume` | `POST /v1/services/{service_uuid}/resume` | `services.edit` |
| `services.runNow` | `POST /v1/services/{service_uuid}/run-now` | `services.edit` |
| `services.testParameters` | `POST /v1/services/{service_uuid}/parameters/test` | `services.edit` |
| `services.testRunsStartNew` | `POST /v1/services/test-runs` | `services.edit` |
| `services.testRunsStartSaved` | `POST /v1/services/{service_uuid}/test-runs` | `services.edit` |
| `services.duplicate` | `POST /v1/services/{service_uuid}/duplicate` | `services.edit` |
| `services.import` | `POST /v1/services/import` | `services.edit` |

### Alarm channels

| Operation | Call | Scope |
| --- | --- | --- |
| `alarmChannels.create` | `POST /v1/alarm-channels` | `channels.edit` |
| `alarmChannels.update` | `PUT /v1/alarm-channels/{channel_uuid}` | `channels.edit` |
| `alarmChannels.sendTest` | `POST /v1/alarm-channels/{channel_uuid}/test` | `channels.edit` |
| `alarmChannels.delete` | `DELETE /v1/alarm-channels/{channel_uuid}` | `channels.delete` |

A channel’s destination URL is write-only, and so is a webhook channel’s signing secret: no answer returns either, only whether a signing secret is set. A channel an alarm policy still notifies cannot be deleted. [Route alarms to Slack](https://developer.watchtower15.com/api/route-alarms-to-slack/) shows the calls in order.

### Alarm policies

| Operation | Call | Scope |
| --- | --- | --- |
| `alarmPolicies.create` | `POST /v1/alarm-policies` | `policies.edit` |
| `alarmPolicies.update` | `PUT /v1/alarm-policies/{policy_uuid}` | `policies.edit` |
| `alarmPolicies.delete` | `DELETE /v1/alarm-policies/{policy_uuid}` | `policies.delete` |

An alarm policy update sends only the fields it changes, and a `notifies` list, when sent, replaces the policy’s targets: read the policy, add to its list and send the whole list back. `notifies` is the policy’s Warning route (it also covers critical incidents while `critical_uses_warning` is true): a `critical` object replaces the whole Critical route, and `critical_uses_warning: true` clears it, as [Send only critical alarms to a channel](https://developer.watchtower15.com/api/route-alarms-to-slack/#send-only-critical-alarms-to-a-channel) shows. The default policy, and a policy an alarm rule or a report uses, cannot be deleted.

### Alarms and profile alarm templates

| Operation | Call | Scope |
| --- | --- | --- |
| `alarms.create` | `POST /v1/alarms` | `alarms.edit` |
| `alarms.update` | `PUT /v1/alarms/{alarm_uuid}` | `alarms.edit` |
| `alarms.delete` | `DELETE /v1/alarms/{alarm_uuid}` | `alarms.delete` |
| `serverProfiles.createAlarmTemplate` | `POST /v1/server-profiles/{server_profile_uuid}/alarm-templates` | `server_profiles.edit` |
| `serverProfiles.updateAlarmTemplate` | `PUT /v1/server-profiles/{server_profile_uuid}/alarm-templates/{template_uuid}` | `server_profiles.edit` |
| `serverProfiles.deleteAlarmTemplate` | `DELETE /v1/server-profiles/{server_profile_uuid}/alarm-templates/{template_uuid}` | `server_profiles.delete` |
| `serverProfiles.previewAlarmTemplatePropagation` | `POST /v1/server-profiles/{server_profile_uuid}/alarm-templates/preview-propagation` | `server_profiles.view` |
| `serverProfiles.propagateAlarmTemplates` | `POST /v1/server-profiles/{server_profile_uuid}/alarm-templates/propagate` | `server_profiles.edit` |

An alarm is created from a catalogue rule named by its slug (`GET /v1/alarm-rules`). An alarm update sends only the fields it changes, and a `null` returns a threshold, window, count or name to the rule’s default; `active` and `alarm_policy_uuids` cannot be `null`. A deleted alarm does not come back. A propagation with `apply_to_all: true` removes, on every server of the profile, the alarms whose template is gone: preview it first. [Quiet a noisy alarm](https://developer.watchtower15.com/api/quiet-a-noisy-alarm/) shows the calls in order.

To find the alarms to change, read them in one call rather than one resource at a time: `GET /v1/organisation/alarms` lists every alarm of the organisation, filtered by `entity_type`, `server_uuid` (a server with its volumes, ports and units), `rule_slug`, `state`, `active` and `policy_uuid`; alarms of deleted resources are not listed. `GET /v1/servers/{server_uuid}/alarms` lists one server’s. On the alarm list `entity_type=server` is the servers’ own alarms (every port’s are `entity_type=server_port`); on `GET /v1/incidents`, `entity_type=server` alone is every server’s incidents with its volumes’, ports’ and units’.

### Incidents

| Operation | Call | Scope |
| --- | --- | --- |
| `incidents.acknowledge` | `POST /v1/incidents/{incident_uuid}/acknowledge` | `incidents.edit` |
| `incidents.resolve` | `POST /v1/incidents/{incident_uuid}/resolve` | `incidents.edit` |

### Databases

| Operation | Call | Scope |
| --- | --- | --- |
| `databases.collectorPreview` | `POST /v1/databases/collector-preview` | `database.edit` |
| `databases.create` | `POST /v1/databases` | `database.edit` |
| `databases.update` | `PUT /v1/databases/{database_uuid}` | `database.edit` |
| `databases.delete` | `DELETE /v1/databases/{database_uuid}` | `database.delete` |
| `databases.verify` | `POST /v1/databases/{database_uuid}/verify` | `database.edit` |
| `databases.reassign` | `POST /v1/databases/{database_uuid}/reassign` | `database.edit` |
| `databases.acceptKey` | `POST /v1/databases/{database_uuid}/accept-key` | `database.edit` |
| `databases.pause` | `POST /v1/databases/{database_uuid}/pause` | `database.edit` |
| `databases.resume` | `POST /v1/databases/{database_uuid}/resume` | `database.edit` |
| `databases.refreshSchema` | `POST /v1/databases/{database_uuid}/schema-refresh` | `database.edit` |
| `databases.runAdvisor` | `POST /v1/databases/{database_uuid}/advisor-run` | `database.edit` |
| `databases.dismissFinding` | `POST /v1/databases/{database_uuid}/findings/{finding_uuid}/dismiss` | `database.edit` |
| `databases.restoreFinding` | `POST /v1/databases/{database_uuid}/findings/{finding_uuid}/restore` | `database.edit` |

### Custom metrics

| Operation | Call | Scope |
| --- | --- | --- |
| `customMetrics.create` | `POST /v1/custom-metrics` | `custom_metrics.edit` |
| `customMetrics.update` | `PUT /v1/custom-metrics/{custom_metric_uuid}` | `custom_metrics.edit` |
| `customMetrics.approve` | `POST /v1/custom-metrics/{custom_metric_uuid}/approve` | `custom_metrics.edit` |
| `customMetrics.resetSeries` | `POST /v1/custom-metrics/{custom_metric_uuid}/reset-series` | `custom_metrics.delete` |
| `customMetrics.discard` | `POST /v1/custom-metrics/{custom_metric_uuid}/discard` | `custom_metrics.delete` |
| `customMetrics.delete` | `DELETE /v1/custom-metrics/{custom_metric_uuid}` | `custom_metrics.delete` |

### Metric sources

| Operation | Call | Scope |
| --- | --- | --- |
| `metricSources.create` | `POST /v1/metric-sources` | `custom_metrics.edit` |
| `metricSources.update` | `PUT /v1/metric-sources/{metric_source_uuid}` | `custom_metrics.edit` |
| `metricSources.previewTagChanges` | `POST /v1/metric-sources/{metric_source_uuid}/preview-tag-changes` | `custom_metrics.edit` |
| `metricSources.rotateToken` | `POST /v1/metric-sources/{metric_source_uuid}/rotate-token` | `custom_metrics.edit` |
| `metricSources.revokeToken` | `POST /v1/metric-sources/{metric_source_uuid}/revoke-token` | `custom_metrics.delete` |
| `metricSources.delete` | `DELETE /v1/metric-sources/{metric_source_uuid}` | `custom_metrics.delete` |

### Log sources

| Operation | Call | Scope |
| --- | --- | --- |
| `logSources.create` | `POST /v1/log-sources` | `log_sources.edit` |
| `logSources.update` | `PUT /v1/log-sources/{log_source_uuid}` | `log_sources.edit` |
| `logSources.rotateToken` | `POST /v1/log-sources/{log_source_uuid}/rotate-token` | `log_sources.edit` |
| `logSources.revokeToken` | `POST /v1/log-sources/{log_source_uuid}/revoke-token` | `log_sources.delete` |
| `logSources.delete` | `DELETE /v1/log-sources/{log_source_uuid}` | `log_sources.delete` |

## What a write answers

| Kind of write | Method | Answers |
| --- | --- | --- |
| Create | `POST` | `201 Created`, with the created object |
| Update | `PUT` | `200`, with the object after the update |
| Delete | `DELETE` | `204 No Content`, with no body |
| An action | `POST` | `200` with the object it changed, or `202 Accepted` when it only queues work, with the object it acts on |

An answer to a write is the same envelope as a read: `{"data": …}`. Failures are the same [problem answers](https://developer.watchtower15.com/api/errors/) as a read’s.

## An update replaces the whole object

A `PUT` sends the complete object, not the fields you want to change. What the console’s update form requires, the `PUT` requires. A field you leave out is cleared, or refused if it is required, so read the object first, change what you need and send all of it back:

```plaintext
curl -H "Authorization: Bearer $WT15_API_KEY" https://rest.watchtower15.com/v1/things/$UUID > thing.json
# edit thing.json: keep every field the update takes
curl -X PUT -H "Authorization: Bearer $WT15_API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" --data @thing.json https://rest.watchtower15.com/v1/things/$UUID
```

(`/v1/things` is an example path: no operation by that name exists.)

## Every write takes an Idempotency-Key

Send an `Idempotency-Key` with every `POST`, `PUT` and `DELETE`: see [Idempotent requests](https://developer.watchtower15.com/api/idempotent-requests/).

## Fields that go in and never come out

Some fields are write-only: a password or a token you send, which the API never returns. They are marked `writeOnly: true` in the [OpenAPI document](https://developer.watchtower15.com/api/reference/), and a read of the object does not carry them. The few answers that show a secret once, as the console does when it makes one, say so on that operation: the secret is in that answer and in no other.

## Following a 202

An action that only queues work answers `202` with the object it acts on, read back after the request: `services.runNow` the service, `databases.refreshSchema` and `databases.runAdvisor` the database, `servers.recheckPosture` the server. Read that object again with its `GET` to see the result. `services.testParameters` answers the test, with `status` `pending`; poll `GET /v1/services/{service_uuid}/parameters/test` until it is finished. `services.testRunsStartNew` and `services.testRunsStartSaved` answer `202` with the test, `waiting`; poll `GET /v1/service-test-runs/{test_uuid}` until its status is `passed`, `failed` or `no_answer`. See [test a service before you save it](https://developer.watchtower15.com/api/changing-resources/#test-a-service-before-you-save-it).

## A refused delete

A delete the console refuses because something still depends on the record answers `422` `invalid_request`, with `errors.dependencies` listing what blocks it as `<what>: <how many>` (`servers: 3` for a server profile that servers use, `default_profile: 1`, `system_group: 1`), and nothing is deleted. `detail` says what blocks it. Remove or move what it names, and the same delete then succeeds.

## A refusal that names a field

A uuid in a body that is not yours, or does not exist, answers `404` `not_found` naming the field, as a uuid in a path does. The guarded actions, `databases.refreshSchema`, `databases.runAdvisor`, `servers.recheckPosture` and `servers.recheckOsUpdates`, refuse a repeat within their own interval with `422` `invalid_request` on their own key (`schema_refresh`, `advisor_run`, `posture_recheck`, `os_updates_recheck`), never `429` with `Retry-After` as a scan does, so a script should not retry them as a rate limit. A verification check inside its cooldown answers the stored verification without a new lookup.

## Examples

**Create a domain.** A body of `name`, and what you want of it:

```plaintext
curl -X POST -H "Authorization: Bearer $WT15_API_KEY" -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" --data '{"name": "example.com"}' https://rest.watchtower15.com/v1/domains
```

It answers `201` with the domain. A create starts charges as in the console.

**Start a domain’s verification.** `authorised` must be `true`: sending it is your organisation’s confirmation under section 5.1 of the Terms and its warranty of control under 5.3. A missing or false value answers `422`: “Confirm that you control this domain and authorise WatchTower15 to scan it.”

**Change a service and send it back whole.** A service is its `steps`. Read the service, change a step and send all of it back, each step with its `uuid`. The view does not return a step’s write-only parts, its header names and values, body, cookies, query string, payloads, messages, metadata and authentication fields: leave them out of the `PUT` and the step keeps them. `null` clears one, a `url` sent without its query keeps the stored query, and a step whose host or port changes must send its write-only parts again, or the call answers `422`. A step the service does not hold is refused: its `uuid` is assigned when it is first saved. Every save writes a new version, live at once; `GET /v1/services/{service_uuid}/versions` lists them and none is ever removed.

**Create a log source, then rotate its token.**

```plaintext
curl -X POST ... --data '{"name": "api-gateway"}' https://rest.watchtower15.com/v1/log-sources
curl -X POST ... -H "Idempotency-Key: rotate-gateway-1" https://rest.watchtower15.com/v1/log-sources/$UUID/rotate-token
```

The rotation answers the new `ingest_token` once. The same `Idempotency-Key` again answers the stored receipt with the token `null`, because WatchTower15 never keeps a secret for a replay. A lost answer therefore needs a new rotation, with a new key, and the same holds for `metricSources.rotateToken`. The server operations `servers.provision` and `servers.rotateToken` are deprecated: each is refused with a `422` `invalid_request` whose `errors.server_uuid` says “This operation is withdrawn and changes nothing. A server gets a new token by enrolling again with the organisation’s install token.”, and changes nothing; they will be removed at the next major release of the SDKs. See [Idempotent requests](https://developer.watchtower15.com/api/idempotent-requests/#answers-that-hold-a-secret).

**A tag cycle.** Create a group, create a tag in it, rename the tag, delete the tag and the group:

```plaintext
POST /v1/tag-groups   {"name": "environment"}
POST /v1/tags         {"tag_group_uuid": "…", "name": "production"}
PUT  /v1/tags/{tag_uuid}   {"name": "prod"}
DELETE /v1/tags/{tag_uuid}
DELETE /v1/tag-groups/{tag_group_uuid}
```

## Test a service before you save it

`POST /v1/services/test-runs` takes the body of a create and runs one check of that definition from one live collector of its pool, saving nothing; `POST /v1/services/{service_uuid}/test-runs` does the same for a saved service, with the body of an update, and a stored secret you do not send is used as saved. Both need `services.edit`, and `services.parameters` for a definition that carries parameters or authentication, and both are refused exactly where the save would be. One test is allowed every 30 seconds, and 20 an hour for the organisation: past that the answer is `429` with `Retry-After`. `GET /v1/service-test-runs/{test_uuid}` (scope `services.view`) reads one of your own tests for the hour after you start it; its result carries each check’s reason and the numbers an assertion observed, and never a value, a resolved address or a response snippet.

A service is one to ten `steps`, each of a type (`http`, `grpc`, `websocket`, `tcp`, `udp`, `icmp`, `dns`, `tls`, `smtp` or `wait`), with up to twenty assertions (`target`, `operator`, `value`), up to ten extractions for the steps after it and its own `on_success`, `on_failure` and `repeat`; `variables` (up to ten) and `run` (a budget of 5 to 300 seconds and a fast retry) belong to the service. A credential is never a literal: it is one `{{param.name}}` reference to a Parameter, and a step’s host and port hold no reference. A limit that is exceeded, or an option on a type that does not use it, answers `422` naming its field. `POST /v1/services/import` makes the step of a pasted cURL command or OpenAPI operation, saves nothing and lists the Parameters it needs; `POST /v1/services/{service_uuid}/duplicate` makes a paused copy. A service with several steps, or with a step type the collectors do not run yet, is stored and readable but is not checked until the collector runner dispatches steps: its health reads `unknown` and it raises no alarm. The view returns the steps; `GET /v1/services/{service_uuid}/collectors` (scope `services.view`) lists the servers of its collector pool with their role, why one is excluded and the time and result of its last check.

## Creating needs a payment method

A create answers `402` when your organisation has no payment method, or has an unpaid invoice past due, with the same two codes as the console: `payment_required` and `invoice_overdue`. So do a server’s approval and reactivation, a custom metric’s approval, and switching monitoring back on (an update that sets `active` to `true`, or a resume). A create that would take you past a limit answers `422` with the code `limit_reached`, naming what you reached. See [Errors](https://developer.watchtower15.com/api/errors/) and [Account limits](https://docs.watchtower15.com/platform/account-limits/).

## Who may write

A key can write only with a write scope: every scope that does not end in `.view` is one. Giving a key a write scope needs the **API access** edit permission, `api_access.edit`, besides the permission itself, and a write by a key is recorded in the [audit trail](https://docs.watchtower15.com/platform/audit-trail/) with the key. A [service account](https://developer.watchtower15.com/api/authentication/#service-accounts) can own such a key. See [authentication and keys](https://developer.watchtower15.com/api/authentication/).

Source: https://developer.watchtower15.com/api/changing-resources/
