ServerPilot API
The ServerPilot’s JSON API allows you to programmatically perform the same server management actions that are available through the ServerPilot dashboard.
API documentation
View the full API documentation.
Generate an API key
The first step to using the API is to get your Client ID and generate an API Key. You will use your Client ID and API Key instead of a username and password when making requests to the ServerPilot API.
To find your Client ID and generate an API Key:
- Log in to the ServerPilot control panel.
- Click on Account > API.
- Click New API Key.
Record your Client ID and API Key now. For security purposes, your API Key will not be shown again. If lost, you will need to generate a new API Key.
You must keep your API key secret.
If you accidentally publish your API key (for example, on GitHub), you can generate a new API key. Generating a new API key will revoke your account’s existing API key.
Use the API
In the examples below, the curl
command is used to perform API requests.
Using curl
is an easy way to demonstrate the API.
For any advanced usage of the API, you may want to use your preferred
programming language to interact with the API.
For all of the examples, we will assign our Client ID and API Key to variables called CLIENTID and APIKEY, respectively. For example, in bash:
export CLIENTID=cid_2398yhfsdfhu3efui3export APIKEY=asdm29ejfleji3ofneihf9hfdisdhf2hejiwfhsdfsdf
Don’t forget to replace the above CLIENTID and APIKEY values with your own.
Example: list servers
curl https://api.serverpilot.io/v1/servers \ -u $CLIENTID:$APIKEY
Example: list apps
curl https://api.serverpilot.io/v1/apps \ -u $CLIENTID:$APIKEY
Example: create an app
curl https://api.serverpilot.io/v1/apps \ -u $CLIENTID:$APIKEY \ -H "Content-Type: application/json" \ -d '{"name": "example", "sysuserid": "RvnwAIfuENyjUVnl", "runtime": "php7.0", "domains": ["example.com", "www.example.com"]}'
Example: connect a server
Connecting a server is a two-step process. First, you use the ServerPilot API to create a Server ID and Server API Key. Second, you run the ServerPilot installer on your server using that Server ID and Server API Key.
To create the Server ID and Server API Key, you would make the following API request:
curl https://api.serverpilot.io/v1/servers \ -u $CLIENTID:$APIKEY \ -H "Content-Type: application/json" \ -d '{"name": "www2"}'
The response will contain the server’s ID and API Key.
Next, you would execute the ServerPilot installer. Detailed steps to do this are shown in the full ServerPilot API Documentation.
By using both ServerPilot’s API and your provider’s API (for example, the DigitalOcean API), you can fully automate provisioning servers and connecting them to ServerPilot.
Example: check the status of an action
API requests, such as “create an app,” that perform work on your server
return an "actionid"
in the response.
{ "actionid": "dIrCNoWunW92lPjw", "data": { ... }}
You can use the "actionid"
to check the completion status of work
being performed on your server for this API request. For example, if
your script needs to wait for the app to be fully created so it can
begin deploying files to an app’s web root directory, you would check
the status of the action to determine when the app is fully created on
your server.
To check the status of an action, use the following API request (replace the actionid in the URL with the actionid you are checking the status of):
curl https://api.serverpilot.io/v1/actions/dIrCNoWunW92lPjw \ -u $CLIENTID:$APIKEY