22.05.2023

How to automate server deployment via API?

List of API Keys

API keys to access your project.

API

Serverspace Public API - a public API for interaction with the Serverspace services. Actions performed in the Serverspace control panel can also be performed using the public API.

Authorization

To work with the public API, create an API key for the project and pass it in the X-API-KEY header with every request. For example, when using the cURL utility, the header would look like this:

-H "X-API-KEY: lmGwbvllpIqIrKROOCLgE5Z941MKP5EYfbkgwtqJZGigfXUTpuYRpNQkCqShmm6r"

All API requests must be made through HTTPS, here is the URL of the endpoint of the public API:

https://api.serverspace.io/


Usage Examples

Let's get information about the project by sending a request using the cURL utility:

curl -X GET \
https://api.serverspace.io/api/v1/project \
-H 'content-type: application/json' \
-H 'x-api-key: lmGwbvllpIqIrKROOCLgE5Z941MKP5EYfbkgwtqJZGigfXUTpuYRpNQkCqShmm6r'

This will return information about the project:

{
"project": {
"balance": 400.07,
"created": "2019-04-08T10:35:53.7021047Z",
"currency": "EUR",
"id": 1,
"state": "Active"
}
}

Let's create a server with the following configuration: Amsterdam, name: "api-example", Debian 10.7 operating system, server configuration - 1 GB RAM, 1 CPU, 25 GB SSD boot drive, 50 Mbps:

curl -X POST \
https://api.serverspace.io/api/v1/servers \
-H 'content-type: application/json' \
-H 'x-api-key: lmGwbvllpIqIrKROOCLgE5Z941MKP5EYfbkgwtqJZGigfXUTpuYRpNQkCqShmm6r' \
-d '{
"location_id": "am2",
"image_id": "Debian-10.7-X64",
"cpu": 1,
"ram_mb": 1024,
"volumes": [
{
"name": "boot",
"size_mb": 25600
}
],
"networks": [
{
"bandwidth_mbps": 50
}
],
"name": "api-example"
}'

The result returns a task ID, which can be used to track the server creation process:

{
"task_id" : "lt1507097"
}