# Troubleshoot Azion API

This page lists the errors you can meet with the [Azion API](/en/documentation/devtools/api/), each with its cause and its fix. Every error response holds an `errors` array. Each item carries a `code`, a `title`, a `detail`, a `status` as a string, and usually a `source`.

---

## A request fails with Authentication credentials were not provided

A request answers `401`, with the header `WWW-Authenticate: Bearer realm="api"` and this body:

```json
{"errors":[{"code":"10002","title":"Not Authenticated","detail":"Authentication credentials were not provided.","status":"401","source":{"headers":"Authorization"}}]}
```

The request has no `Authorization` header. Code `10002` and `"source":{"headers":"Authorization"}` name the missing header.

- **Send the token header**: add `Authorization: Token [TOKEN VALUE]` to every request, with your personal token in place of `[TOKEN VALUE]`.
- **Use the Bearer scheme if your client needs it**: the API also accepts a personal token as `Authorization: Bearer [TOKEN VALUE]`.
- **Get a personal token**: create one in Azion Console or with the Azion CLI. For the steps, refer to [Manage personal tokens](/en/documentation/guides/platform/account-and-billing/personal-tokens/).

The same request then answers `200`.

---

## A request fails with Invalid authentication credentials

A request that sends an `Authorization` header answers `401`, with the header `WWW-Authenticate: Bearer realm="api"` and this body:

```json
{"errors":[{"code":"10001","title":"Authentication Failed","detail":"Invalid authentication credentials.","status":"401","source":{"headers":"Authorization"}}]}
```

The header is present, but the API does not accept the token it carries. Code `10001` separates this case from a missing header, which returns code `10002`.

- **Check the token value**: compare the token in the header with the token you saved when you created it.
- **Replace the token**: create a personal token and send it in the header. For the steps, refer to [Manage personal tokens](/en/documentation/guides/platform/account-and-billing/personal-tokens/).

With a valid token, the same request answers `200`.

---

## A list fails with Page size must be between 0 and 100

`GET https://api.azion.com/v4/workspace/workloads?page_size=1000&fields=id` answers `400` with this body:

```json
{"errors":[{"code":"10097","title":"Invalid Page Size","detail":"Page size must be between 0 and 100.","status":"400","source":{"pointer":"/data"}}]}
```

The `page_size` query parameter is above the maximum. A list returns at most 100 items per page, and 10 when you omit `page_size`.

- **Lower the page size**: send `page_size=100` or less.
- **Read the rest page by page**: send `page=2`, `page=3`, and so on, up to the `total_pages` value of the response.

The list answers `200`, and the `page_size` field of the response echoes the value you sent.

---

## A list fails with Not found after the last page

A list request with a high `page` value answers `404`. A `GET` with a `page` past `total_pages`, such as `GET https://api.azion.com/v4/workspace/workloads?page=99`, answers this body:

```json
{"errors":[{"code":"10004","title":"Not Found","detail":"Not found.","status":"404","source":{"pointer":"/data"}}]}
```

The `page` value is greater than the number of pages the list has. This `404` carries `"source":{"pointer":"/data"}`, and a `404` for a missing resource has none.

- **Read the page count first**: request page 1 and read `total_pages` and `count` from the response.
- **Stop at the last page**: increase `page` until it equals `total_pages`. With a larger `page_size`, the list has fewer pages.

Every page from 1 to `total_pages` answers `200`.

---

## A resource request fails with Not found

A request for one resource by its ID answers `404`. A `GET` with an ID that does not exist, such as `GET https://api.azion.com/v4/workspace/network_lists/999999999`, answers this body:

```json
{"errors":[{"code":"10004","title":"Not Found","detail":"Not found.","status":"404"}]}
```

No resource with that ID exists in the account. A resource you deleted returns the same body: after a `DELETE`, a `GET` on the same path answers this `404`. The response has no `source` member, unlike the `404` of a page past the end of a list.

- **Find the ID in the list**: list the collection, for example `GET https://api.azion.com/v4/workspace/network_lists`, and copy the `id` from `results`.
- **Shorten the list**: add `fields=id,name` to return only the ID and the name of each item.

With an ID from the list, the request answers `200` and returns the resource in `data`.

---

## A request fails with Method not allowed

A request answers `405`. A `DELETE` on a collection path, such as `DELETE https://api.azion.com/v4/workspace/network_lists`, answers with the header `Allow: GET, POST` and this body:

```json
{"errors":[{"code":"10007","title":"Method Not Allowed","detail":"Method \"DELETE\" not allowed.","status":"405","source":{"pointer":"/data"},"meta":{"method":"DELETE"}}]}
```

A `POST` on an item path, such as `POST https://api.azion.com/v4/workspace/network_lists/<network-list-id>`, answers with the header `Allow: GET, PUT, PATCH, DELETE` and this body:

```json
{"errors":[{"code":"10007","title":"Method Not Allowed","detail":"Method \"POST\" not allowed.","status":"405","source":{"pointer":"/data"},"meta":{"method":"POST"}}]}
```

The path does not take the method you sent, which `meta.method` names. A collection path and an item path take different methods.

- **Use a method from the Allow header**: the `Allow` header of the response lists the methods the path takes.
- **Create on the collection**: send `POST` to the collection path, such as `/v4/workspace/network_lists`.
- **Change or delete on the item**: send `PUT`, `PATCH`, or `DELETE` to the item path, such as `/v4/workspace/network_lists/<network-list-id>`.

With a method from the `Allow` header, the request answers `200`, or `201` for a create.

---

## Related resources

- [Azion API](/en/documentation/devtools/api.md): The base URL, the authentication header, and the page size and rate limits that several fixes rely on.
- [Azion API quickstart](/en/documentation/devtools/api/quickstart.md): A first request, then a create, read, update, and delete of a network list, with every response.
- [Manage personal tokens](/en/documentation/guides/platform/account-and-billing/personal-tokens.md): Create the personal token that authenticates your requests, from Azion Console or the Azion CLI.
- [Azion API reference](https://api.azion.com/): Every path, method, parameter, and response of the API.
