# Azion API

> Platform versions: this page applies to API v6.x only, not to API v4.x and API v3.x.
> Equivalent page for API v4.x: [Azion API](/en/documentation/devtools/api.md)
> Release stage: Preview.

An application programming interface (API) lets a program act on a service without its web interface. A REST API gives each object of the service its own URL. The client reads the object with `GET`, creates it with `POST`, changes it with `PUT` or `PATCH`, and removes it with `DELETE`. Because every action is an HTTP request, the same call runs from a terminal, a script, or a CI/CD pipeline.

**Azion API** exposes the resources of your Azion account as a REST API over HTTPS, at the base URL `https://api.azion.com/v6`. Each request carries a personal token or an access token, and responses return JSON. Besides the resources under `/workspace`, the API serves deployments, environments, variables, and resource usage at the root of the base URL. Use the Azion API to manage the resources of your account, such as applications, firewalls, and workloads, and to publish versions through releases.

[Get started](/en/documentation/devtools/api/quickstart/v6/)

[Go to the API reference](https://api.azion.com/v6)

---

## Request structure

A request names a resource path under the base URL and sends the personal token in a header. This request lists the IDs of the workloads in an account:

```bash
curl --request GET \
  --url 'https://api.azion.com/v6/workspace/workloads?page_size=100&fields=id' \
  --header 'Accept: application/json' \
  --header 'Authorization: Token [TOKEN VALUE]'
```

A `200` returns one page of results:

```json
{
  "count": 3,
  "total_pages": 1,
  "page": 1,
  "page_size": 100,
  "next": null,
  "previous": null,
  "results": [
    {"id": 1234567890},
    {"id": 1234567891},
    {"id": 1234567892}
  ]
}
```

- **Path**: most resource endpoints sit under `/v6/workspace/`, such as `/v6/workspace/workloads` and `/v6/workspace/network_lists`. Deployments, environments, variables, and resource usage sit at the root, such as `/v6/deployments` and `/v6/variables`. Login and tokens sit under `/v6/account/`.
- **Header**: `Authorization` carries the personal token with the `Token` scheme.
- **Query parameters**: `page_size=100` asks for up to 100 results on the page, and `fields=id` keeps only the `id` of each result.
- **List envelope**: `count` is the number of workloads in the account, `total_pages` and `page` place the page in the list, and `results` holds the workloads. `next` and `previous` are `null` because the list has one page.

If you have called a REST API that returns JSON, the model transfers unchanged: a method, a URL, a credential header, and a JSON body. The [Azion API reference](https://api.azion.com/v6) lists every path, method, parameter, and response. The API serves its OpenAPI specification at `https://api.azion.com/v6/openapi/openapi.yaml`, which declares version `6.0.0`.

---

## Methods and responses

Most endpoints take the same methods, split between a collection path and an item path. The status of a successful response tells whether the change is already done:

- **Methods**: a collection path, such as `/v6/workspace/network_lists`, takes `GET` to list and `POST` to create. An item path, such as `/v6/workspace/network_lists/<network-list-id>`, takes `GET`, `PUT`, `PATCH`, and `DELETE`. Another method returns `405` with code `10007`, and the `Allow` header of the response lists the methods the path takes.
- **Version actions**: a resource with versions takes a `POST` on the path of each action, such as `/v6/workspace/network_lists/<network-list-id>/versions/<version-id>/build`. Applications, connectors, custom pages, firewalls, functions, network lists, and WAFs take `build`, `cancel`, and `archive`. Workloads, certificates, CRLs, environments, deployments, and variables take `revert`, which clones an archived version and makes the clone active.
- **Response bodies**: a request for one resource returns it inside `data`. A variable and a version return their fields at the top level of the body instead, with `version_id` and `version_state`.

Each operation returns one of four success statuses. The reference lists the status of each operation:

| Status | Meaning                                                                                                                                                                                     |
| ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `200`  | The API read, changed, or deleted the resource before it answered.                                                                                                                          |
| `201`  | The API created the resource before it answered.                                                                                                                                            |
| `202`  | The API accepted the request and processes it asynchronously, after it answers. Creating an Application and deleting one return `202`, and so do building a version and deleting a version. |
| `204`  | The API deleted the resource, and the response has no body. Deleting a network list returns `204`.                                                                                          |

---

## Errors

An error returns an `errors` array. Each item carries a `code`, a `title`, a `detail`, and a `status` written as a string. An item can also carry a `source`, which names the header or the field at fault, and a `meta` object with more details:

```json
{
  "errors": [
    {
      "code": "10105",
      "title": "Version Not Editable",
      "detail": "Cannot edit a version that is not in draft state.",
      "status": "409",
      "source": {
        "pointer": "/data"
      }
    }
  ]
}
```

A request that conflicts with the state of a version returns `409`. The `code` names the conflict:

| Code    | Title                  | Cause                                                          |
| ------- | ---------------------- | -------------------------------------------------------------- |
| `10101` | Max Drafts Exceeded    | The resource has reached its maximum number of draft versions. |
| `10102` | Version Deployed       | The request changes a version that is in use.                  |
| `10105` | Version Not Editable   | The request edits a version that is not in the `draft` state.  |
| `10106` | Version Already Built  | The version is already built, or its build is in progress.     |
| `10107` | Version Not Archivable | The version cannot be archived in its current state.           |

The versions of a resource return three more errors. A `403` with code `10104` means that resource versioning is not enabled for the account. A `400` with code `10108` means that the resource is not versioned. A `400` with code `10111` names a feature that is not available.

Deployments endpoints also return `409` when a deployment with the same name already exists. They return it too when a request changes the policy of a deployment that has active versions. A release returns `409` while it is building or being removed, when the draft limit is reached, or while its deployment is being deleted.

A Variables endpoint can return `503` with code `10100` while the service is temporarily unavailable. Deployments, Environments, and Resource Usage endpoints can return `504` with code `10067`.

---

## Authentication

Every request to the Azion API carries a credential in the `Authorization` header. A [personal token](/en/documentation/fundamentals/personal-tokens/) takes the `Token` scheme:

```text
Authorization: Token [TOKEN VALUE]
```

The API also takes the `Bearer` scheme, with a personal token or with an access token, as `Authorization: Bearer [TOKEN VALUE]`. An access token is a JWT that `POST /v6/account/auth/login` returns, and `POST /v6/account/auth/token` issues a new one from the refresh token. You create a personal token in Azion Console. To create one, refer to [Manage personal tokens](/en/documentation/guides/platform/account-and-billing/personal-tokens/).

A request without the header returns `401` with code `10002`. Under `/v6/workspace/` and `/v6/variables`, a request whose token the API does not accept returns `401` with code `10001` and the header `WWW-Authenticate: Bearer realm="api"`. Under `/v6/deployments`, `/v6/environments`, and `/v6/resource_usage`, the same request returns `401` with code `10002` and `Invalid token` in `detail`.

---

## Pagination and query parameters

A list request returns one page of results, and five query parameters choose which page and what each result holds. The page count comes back in `total_pages`. `next` and `previous` hold the URL of the next and the previous page, or `null` when no such page exists. To read the following page, send the request in `next`, or send the same request with `page` increased by one.

| Parameter   | Effect                                                                                                                                                                           |
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `page`      | Selects one page of the list, counted from `1`.                                                                                                                                  |
| `page_size` | Sets the number of results per page, from `1` to `100`. Without it, a list returns 10 results per page.                                                                          |
| `fields`    | Returns the fields that a comma-separated list names, such as `fields=id,name`.                                                                                                  |
| `ordering`  | Sorts the list by one field, such as `ordering=name`. A `-` before the field, as in `ordering=-name`, reverses the order. The reference lists the fields that each list accepts. |
| `search`    | Narrows the list to the results that match a search term. The reference lists the fields that each list searches, such as `name` and `last_editor`.                              |

On a list whose reference names the accepted fields, an `ordering` value that names another field returns `400` with code `10088`. The `meta` of the error lists the accepted fields. Lists also take filters of their own, such as `name`, `last_modified__gte`, and `last_modified__lte`.

---

## Limits

A list takes up to 100 results per page. A `page_size` outside the range from `1` to `100` returns `400` with code `10097`. The range is the same on a list of resources and on a list of versions.

Two other bounds return an error past them. A request body larger than a Deployments or Environments endpoint accepts returns `413` with code `10112`. A request over the rate the API accepts returns `429` with code `10010`. Responses under `/v6/workspace/` and `/v6/account/` carry the headers `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset`, and `X-RateLimit-Scope`, which give the rate limit that applies to the request.

---

## Next steps

- [Azion API quickstart](/en/documentation/devtools/api/quickstart/v6.md): Send your first requests, then create, rename, and delete a network list.
- [Manage personal tokens](/en/documentation/guides/platform/account-and-billing/personal-tokens.md): Create the token that authenticates every request.
- [Troubleshoot Azion API](/en/documentation/devtools/api/troubleshooting/v6.md): Fix a request that fails with 401, 400, 404, 405, 406, or 409.
- [Glossary](/en/documentation/devtools/api/glossary/v6.md): Look up a term that the API uses.
- [Azion API reference](https://api.azion.com/v6): Look up the path, method, status, and fields of any endpoint.
