# Organisation

The organisation the key acts in: its account type, its limits and what is used, and, for a key that may see billing, its billing details.

Its operations need the scope `alarms.view`.

**Endpoints**

- `GET/v1/organisation`
- `GET/v1/organisation/alarms`

## Get the calling organisation

GET/v1/organisation

Returns the organisation the key acts in: its uuid and name, its account type, its data region, its limits with what is used and, only for a key that holds `billing.view`, its billing currency and billing emails. It takes no parameters and needs no permission for the base fields.

### Returns

`200 OK`:

The organisation, its account type, its data region, its limits and, with `billing.view`, its billing details.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**GET /v1/organisation**

curl:

```bash
curl https://rest.watchtower15.com/v1/organisation \
  -H "Authorization: Bearer $WT15_API_KEY"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

$result = $wt15->organisation->view();
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

const result = await wt15.organisation.view();
```

Python:

```python
client = Client.from_environment()

result = client.organisation.view()
```

**Response (200 OK)**

```json
{
  "data": {
    "uuid": "75666699-b77d-4631-b576-041e8102a55b",
    "name": "example",
    "account_type": "courtesy_trial",
    "data_region": "uk",
    "courtesy_until": 1794214800000,
    "billing": {
      "currency": "example",
      "emails": [
        "example"
      ]
    },
    "limits": {
      "resources": {},
      "api": {
        "per_key_per_minute": 1,
        "per_organisation_per_minute": 1,
        "per_day": {
          "limit": 1,
          "used": 1,
          "resets_at": 1794214800000
        }
      }
    }
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the domains.edit scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

## List the organisation's alarms

GET/v1/organisation/alarms

Lists every alarm of the organisation in one paged call, with each alarm’s thresholds, live state, resource and the policies it notifies. Filter by `entity_type` (one kind of resource; `server` is the servers’ own alarms), `server_uuid` (one server with its volumes, ports and systemd units), `rule_slug` (one or more), `active`, `state` (one or more) and `policy_uuid`. Alarms of deleted resources are not listed. For one resource’s alarms use `GET /v1/alarms`; `GET /v1/servers/{server_uuid}/alarms` also lists a server’s alarms with its children’s. Pages by `page` and `per_page` (`limit` is the same as `per_page`); every page carries `current_page`, `per_page`, `last_page` and `total`.

Needs the scope `alarms.view`.

### Query parameters

- `entity_type` (string or null): Only alarms on this kind of resource: one of `domain`, `service`, `server`, `log_source`, `custom_metric`, `database_instance`, `server_port`, `server_system_service` or `server_volume`. `server` is the servers’ own alarms only; for a server with its volumes, ports and units send `server_uuid`, and for every port `server_port`. Every kind when omitted. Alarms of deleted resources are not listed. Values:`domain``service``server``log_source``custom_metric``database_instance``server_port``server_system_service``server_volume`(an open set: new values may be added)
- `server_uuid` (string (uuid) or null): Only the alarms of this server and of its volumes, ports and systemd units. With `entity_type`, only `server`, `server_volume`, `server_port` or `server_system_service`. Alarms of removed volumes, ports and units are not listed.
- `rule_slug` (array of strings or null): Only alarms on these catalogue rules, by `rule_slug`; every rule when omitted. A bare value is read as a one-item list. A list: repeat the parameter (`rule_slug=<value>&rule_slug=<value>`) or send one value (`rule_slug=<value>`); `rule_slug[]=<value>` is accepted too.
- `active` (string or null): Only alarms that are switched on (`true`) or off (`false`); both when omitted. Values:`true``false``1``0`(an open set: new values may be added)
- `state` (array of strings or null): Only alarms in these live states: `ok`, `warning`, `critical` or `inactive`; every state when omitted. A bare value is read as a one-item list. A list: repeat the parameter (`state=ok&state=warning`) or send one value (`state=ok`); `state[]=ok` is accepted too. Values:`ok``warning``critical``inactive`(an open set: new values may be added)
- `policy_uuid` (string (uuid) or null): Only the alarms that notify this alarm policy.
- `limit` (integer or null): The same as `per_page`, kept for existing clients.
- `include_total` (string or null): Ignored: `total` is always present. Values:`true``false``1``0`(an open set: new values may be added)
- `per_page` (integer or null): How many items one page holds, from 1 to 100; 25 when omitted.
- `page` (integer or null): The page to read, from 1; 1 when omitted. A page past the last answers no rows.

### Returns

`200 OK`:

One page of the organisation’s alarms.

Each item of the page:

- `uuid` (string): The alarm’s uuid.
- `name` (string): The alarm’s own name, else its rule’s.
- `rule_slug` (string): The catalogue rule’s slug.
- `classification` (string): The catalogue rule’s classification: one of `operations`, `security`, `monitoring`. On a server it decides which of the server’s three healths an open incident moves; the other resources keep one health that counts every classification.
- `metric_name` (string): The catalogue rule’s name.
- `description` (string or null): The catalogue rule’s description; null when it has none.
- `alarm_type` (string or null): `boolean` or `threshold`, as the catalogue rule says.
- `unit` (string or null): The unit of the thresholds; null when the rule has none.
- `comparison_operator` (string): How a reading is compared with the thresholds: the alarm’s own operator, else the rule’s default.
- `aggregation` (string or null): How the readings in a window are combined before the comparison; null when the alarm sets none.
- `warning_threshold` (number or null): The alarm’s own value, else the rule’s default.
- `critical_threshold` (number or null): The alarm’s own value, else the rule’s default.
- `warning_window_minutes` (integer or null): The window, in minutes, the warning threshold is judged over; null when the alarm has none.
- `critical_window_minutes` (integer or null): The window, in minutes, the critical threshold is judged over; null when the alarm has none.
- `warning_consecutive_failures_count` (integer): Consecutive evaluations before a warning: the alarm’s own count, else the rule’s default.
- `critical_consecutive_failures_count` (integer): Consecutive evaluations before a critical: the alarm’s own count, else the rule’s default.
- `self_resolving` (boolean): Whether the alarm clears itself when the condition ends (it sends no resolve notification).
- `active` (boolean): Whether the alarm is switched on.
- `notify_on_acknowledge` (boolean): Whether acknowledging an incident of this alarm notifies: the alarm’s own flag, else the catalogue’s. Never null.
- `notify_on_resolve` (boolean): Whether resolving an incident of this alarm notifies: the alarm’s own flag, else the catalogue’s. Never null.
- `entity` (object): The resource the alarm is on, of any type that has alarms.
  - `type` (string): The type of the resource, such as `server`.
  - `uuid` (string or null): The uuid of the resource; null when it no longer resolves.
  - `name` (string or null): The name of the resource; null when it no longer resolves.
- `parent_entity` (object or null): The server of a volume, port or unit; null for every other resource.
  - `type` (string): The type of the server, such as `server`.
  - `uuid` (string): The uuid of the server.
- `alarm_policies` (array of objects): The policies the alarm notifies. A caller holding `policies.view` (the key’s scope and the user’s permission) gets each policy’s `name`; without it, the uuid alone.
  - `uuid` (string): The policy’s uuid.
  - `name` (string): The policy’s name; present only for a caller holding `policies.view`.
- `state` (string): One of `ok`, `warning`, `critical`, `inactive`. Values:`critical``warning``ok``inactive`(an open set: new values may be added)
- `inactive_reason` (string or null): `switched_off` or `resource_inactive` while `state` is `inactive`; null otherwise.
- `state_since` (integer or null): Epoch milliseconds: when the open incident was triggered, while `state` is `warning` or `critical`; null otherwise. An instant: epoch milliseconds, UTC.
- `acknowledged` (boolean): Whether the open incident has been acknowledged.

Each failure is a problem document with a stable `code`; the response panel's status selector shows each one this operation can answer, and [errors](https://developer.watchtower15.com/api/errors/) lists them all.

**GET /v1/organisation/alarms**

curl:

```bash
curl https://rest.watchtower15.com/v1/organisation/alarms \
  -H "Authorization: Bearer $WT15_API_KEY"
```

PHP:

```php
$wt15 = WatchTower15\Client::fromEnvironment();

foreach ($wt15->organisation->alarms()->autoPaging() as $item) { echo $item->uuid, "\n"; }
```

Node.js:

```ts
const wt15 = WatchTower15.fromEnvironment();

for await (const item of wt15.organisation.alarms()) {
  console.log(item.uuid);
}
```

Python:

```python
client = Client.from_environment()

for item in client.organisation.alarms():
    print(item.uuid)
```

**Response (200 OK)**

```json
{
  "data": [
    {
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "name": "example",
      "rule_slug": "example",
      "classification": "example",
      "metric_name": "example",
      "description": "example",
      "alarm_type": "example",
      "unit": "example",
      "comparison_operator": "example",
      "aggregation": "example",
      "warning_threshold": 0,
      "critical_threshold": 0,
      "warning_window_minutes": 1,
      "critical_window_minutes": 1,
      "warning_consecutive_failures_count": 1,
      "critical_consecutive_failures_count": 1,
      "self_resolving": true,
      "active": true,
      "notify_on_acknowledge": true,
      "notify_on_resolve": true,
      "entity": {
        "type": "example",
        "uuid": "75666699-b77d-4631-b576-041e8102a55b",
        "name": "example"
      },
      "parent_entity": {
        "type": "example",
        "uuid": "75666699-b77d-4631-b576-041e8102a55b"
      },
      "alarm_policies": [
        {
          "uuid": "75666699-b77d-4631-b576-041e8102a55b",
          "name": "example"
        }
      ],
      "state": "critical",
      "inactive_reason": "example",
      "state_since": 1794214800000,
      "acknowledged": true
    }
  ],
  "current_page": 1,
  "per_page": 1,
  "last_page": 1,
  "total": 1,
  "meta": {
    "entity": {
      "type": "example",
      "uuid": "75666699-b77d-4631-b576-041e8102a55b",
      "name": "example"
    }
  }
}
```

**Response (401 Unauthorized)**

The API key is missing, malformed, expired or revoked.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (403 Forbidden)**

The key or its owner does not hold what the operation needs.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/forbidden/",
  "title": "Forbidden",
  "status": 403,
  "code": "forbidden",
  "detail": "This key does not have the alarms.view scope",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (404 Not Found)**

No such record in this organisation (an absent id and another organisation's answer alike).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/not_found/",
  "title": "Not found",
  "status": 404,
  "code": "not_found",
  "detail": "No record with that id exists in this organisation.",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

**Response (422 Unprocessable Content)**

The request is invalid (`invalid_request`; `errors` names the parameters).

```json
{
  "type": "https://docs.watchtower15.com/api/errors/invalid_request/",
  "title": "Invalid request",
  "status": 422,
  "code": "invalid_request",
  "detail": "The request is invalid",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "errors": {
    "name": [
      "The name field is required."
    ]
  }
}
```

**Response (429 Too Many Requests)**

A rate limit or the organisation's daily limit is reached; `Retry-After` says when to retry.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/rate_limited/",
  "title": "Rate limited",
  "status": 429,
  "code": "rate_limited",
  "detail": "Too many requests: the limit is 240 a minute",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d",
  "limit": 60
}
```

**Response (500 Internal Server Error)**

An unexpected error.

```json
{
  "type": "https://docs.watchtower15.com/api/errors/internal_error/",
  "title": "Internal error",
  "status": 500,
  "code": "internal_error",
  "detail": "An unexpected error has happened",
  "request_id": "4d1e8b7a-2c9f-4a3e-b6d5-7f0c1a2e3b4d"
}
```

Source: https://developer.watchtower15.com/api/reference/organisation/
