# API

The RESTful API of Ella PSAP, under `/api/v1`, and the [incident data](<https://docs.ellanetworks.com/psap/reference/api/incident_data/index.md>) shared with other agencies, under `/IncidentData`.

## Authentication

Requests send a token in the `Authorization` header:

```
Authorization: Bearer <token>
```

The token is either:

- an access token, from [log in](<https://docs.ellanetworks.com/psap/reference/api/auth/index.md#log-in>), [refresh the access token](<https://docs.ellanetworks.com/psap/reference/api/auth/index.md#refresh-the-access-token>) or [initialize](<https://docs.ellanetworks.com/psap/reference/api/initialize/index.md>), valid for 15 minutes;
- an [API token](<https://docs.ellanetworks.com/psap/reference/api/users/index.md#create-an-api-token>), which starts with `ellapsap_`.

These paths take no token: `GET /IncidentData/Versions`, `GET /api/v1/livez`, `GET /api/v1/readyz`, `GET /api/v1/status`, `GET /api/v1/metrics`, `GET /api/v1/openapi.yaml`, `POST /api/v1/init`, `POST /api/v1/auth/login`, `/refresh` and `/logout`, and `GET /api/v1/auth/oidc`, `/oidc/login` and `/oidc/callback`.

### Roles

The roles a user can have.

| Role | `role_id` | Allows |
| --- | --- | --- |
| Admin | `1` | Everything. |
| Call Taker | `2` | Handling [incidents](<https://docs.ellanetworks.com/psap/reference/api/incidents/index.md>), with their [calls](<https://docs.ellanetworks.com/psap/reference/api/calls/index.md>), [texts](<https://docs.ellanetworks.com/psap/reference/api/texts/index.md>) and [AML reports](<https://docs.ellanetworks.com/psap/reference/api/aml/index.md>), and managing their own password and [availability](<https://docs.ellanetworks.com/psap/reference/api/users/index.md#update-my-availability>). |
| Dispatch System | `3` | [Listing incidents](<https://docs.ellanetworks.com/psap/reference/api/incidents/index.md#list-incidents>) and [retrieving their EIDOs](<https://docs.ellanetworks.com/psap/reference/api/incident_data/index.md>), with an API token only. |

## Responses

Ella PSAP's API responses are JSON objects. A successful response carries a `result`:

```
{
    "result": "Result content"
}
```

A failed response carries an `error`:

```
{
    "error": "Error message"
}
```

## OpenAPI Specification

An [OpenAPI 3.1](<https://spec.openapis.org/oas/v3.1.0>) specification describes the full API:

```
GET /api/v1/openapi.yaml
```

## Status codes

HTTP status codes the API answers with.

- 200 - Success.
- 201 - Created.
- 204 - No content.
- 400 - Bad request.
- 401 - Unauthorized.
- 403 - Forbidden.
- 404 - Not found.
- 405 - Method not allowed.
- 409 - Conflict.
- 429 - Too many requests.
- 500 - Internal server error.
- 502 - Bad gateway.
- 503 - Not ready. See [Check readiness](<https://docs.ellanetworks.com/psap/reference/api/status/index.md#check-readiness>).
