/cloud/stack/add


POST https://api.sitehost.nz/1.2/cloud/stack/add.json

Creates a new stack.

Form Parameters

ParameterTypeRequiredDescription
client_idintegerYesThe ID for the client that the stack will belong to.Example: 1
serverstringYesThe server to create the stack on.Example: ch-servername
namestringYesA name for the new stack. Use /stack/generate_name to create the name.Example: examplenz
labelstringYesAn optional label for the stack. The name will be used if this is not provided.Example: examplenz
enable_sslintegerYesSpecifies whether or not to enable SSL on the new stackExample: 1
docker_composestringYesA docker compose file describing the containers in this stack.
environments[filename.env]stringOne or more environment files to be imported by the Docker Compose.
The key must be the desired file name, while the content must be valid YAML with all the varaibles and their values within a 'vars:' section.
For your variables to show in the Control Panel, you must put them in [name].env using the same value as in the name field above, as this is the only managed .env file.Example:
vars:
  VAR_KEY_1: value1
  TEST_VAR_2: test value

Code Samples

JavaScript PHP Rails Python
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "https://api.sitehost.nz/1.2/cloud/stack/add.json", false);

var data = new FormData();
data.append("apikey", "your_key_here");
data.append("client_id", "1");
data.append("server", "ch-servername");
data.append("name", "examplenz");
data.append("label", "examplenz");
data.append("enable_ssl", "1");
data.append("docker_compose", "");
data.append("environments[filename.env]", "
vars:
  VAR_KEY_1: value1
  TEST_VAR_2: test value");

xmlHttp.send(data);

var response = xmlHttp.responseText;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sitehost.nz/1.2/cloud/stack/add.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$body = array(
'apikey' => 'your_key_here',
'client_id' => 1,
'server' => 'ch-servername',
'name' => 'examplenz',
'label' => 'examplenz',
'enable_ssl' => 1,
'docker_compose' => '',
'environments[filename.env]' => '
vars:
  VAR_KEY_1: value1
  TEST_VAR_2: test value',
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

$response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
require 'net/http'
require 'uri'

uri = URI.parse("https://api.sitehost.nz/1.2/cloud/stack/add.json")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)

body = {"apikey" => "your_key_here",
"client_id" => 1,
"server" => "ch-servername",
"name" => "examplenz",
"label" => "examplenz",
"enable_ssl" => 1,
"docker_compose" => "",
"environments[filename.env]" => "
vars:
  VAR_KEY_1: value1
  TEST_VAR_2: test value",
}
request.set_form_data(body)

response = http.request(request)
import requests
from collections import OrderedDict

uri = 'https://api.sitehost.nz/1.2/cloud/stack/add.json'

# We need ordered dictionary because parameters have to be in the right order.
# Refer to Developer Notes for more information.
body = OrderedDict()

body['apikey'] = 'your_key_here'
body['client_id'] = 1
body['server'] = 'ch-servername'
body['name'] = 'examplenz'
body['label'] = 'examplenz'
body['enable_ssl'] = 1
body['docker_compose'] = ''
body['environments[filename.env]'] = '
vars:
  VAR_KEY_1: value1
  TEST_VAR_2: test value'

response = requests.post(uri, data=body)

Response

200:

application/json
{
  "return": {
    "job_id": "3433562"
  },
  "msg": "Successful",
  "status": true
}