Azion API quickstart
Authenticate to the Azion API with a personal token, list your workloads, and create, read, rename, and delete a network list.
This guide instructs you through your first requests to the Azion API.
- Get a personal token to authenticate your requests.
- List the workloads of your account.
- Create a network list.
- Read the network list and rename it.
- Delete the network list and confirm that it is gone.
Every request goes to the base URL https://api.azion.com/v4 and carries your personal token in the Authorization header. The guide creates one object, a network list with one IP address, and links it to nothing else. You delete it in the last stage, so the account ends as it started.
The Azion CLI gets the same results from the terminal. Each stage shows the API request and the CLI command that matches it. For every endpoint, with request examples in curl and other languages, refer to the Azion API reference.
Choose API or CLI once. The prerequisites and the five stages switch to that interface.
Prerequisites
- An Azion account. To create one, refer to Create an account.
curl, or another HTTP client.
Get a personal token
A personal token authenticates your requests to the Azion API and the Azion CLI. To create one in Azion Console, refer to Manage personal tokens. Copy the token when Azion Console shows it, because you can only see it when you create it.
The Azion API reads the token from the Authorization header. Every request in this guide sends it in this form:
The API also accepts a personal token with the Bearer scheme: Authorization: Bearer [TOKEN VALUE]. You have the header that authenticates every request in the next stages.
List your workloads
A list request returns the workloads of your account and confirms that the token works. The response is one page of results.
Send a GET request to the workloads endpoint. The page_size=100 parameter asks for up to 100 workloads on one page, and fields=id returns only the ID of each workload:
A 200 returns the page of workloads:
The count field holds the number of workloads in the account, and results holds the workloads of the page. A list response carries count, total_pages, page, page_size, next, previous, and results. For pagination, fields, ordering, and search, refer to Azion API.
Create a network list
A network list holds a set of values of one type. The request needs a name, a type, and the items of the list. The type takes ip_cidr, asn, or countries, and items takes from 1 to 20,000 entries. This guide creates an ip_cidr list with one address from the documentation range 192.0.2.0/24.
Send a POST request to the network lists endpoint:
A 201 returns the network list inside data, with "state": "executed":
The active field defaults to true when the request omits it. Record the id. The next stages send it in the URL.
Read and rename the network list
Reading the network list returns its current values. A rename changes one field and leaves the others as they are.
Send a GET request to the network list. Replace <network-list-id> with the id the create request returned:
A 200 returns the network list inside data:
To rename the network list, send a PATCH request with the new name only:
A 200 returns the network list with the new name and a new last_modified:
The type and items fields keep the values of the create request.
Delete the network list
Deleting the network list returns the account to the state it had before you created the list.
Send a DELETE request to the network list:
A 200 returns only the state of the operation:
To confirm the deletion, send the GET request that read the list again. A 404 returns the error envelope:
The network list no longer exists.