/server/firewall/security_groups/update


POST https://api.sitehost.nz/1.5/server/firewall/security_groups/update.json

Update a Security Group.

Please note, you must provide a list of rules to the params[rules_in] and params[rules_out] parameters. All existing rules will be replaced with the values you provide. If you provide nothing, all rules will be deleted.

Form Parameters

ParameterTypeRequiredDescription
client_idintegerYesThe ID for the client.Example: 1
namestringYesThe name of the Security Group.Example: sgfc40e62092
params[label]stringThe new label for the Security Group.Example: My New Security Group Label
params[rules_in][0][enabled]booleanWhether this inbound rule is enabled or not. This parameter accepts one or more values in the format of params[rules_in][0][enabled]=1, params[rules_in][1][enabled]=1.Example: 1
params[rules_in][0][action]enum[ACCEPT, DROP, REJECT]The action for this inbound rule. The following values are accepted: "ACCEPT", "DROP", "REJECT". This parameter accepts one or more values in the format of params[rules_in][0][action]=DROP, params[rules_in][1][action]=ACCEPT.Example: ACCEPT
params[rules_in][0][protocol]enum[tcp, udp]The protocol for this inbound rule. The following values are accepted: "tcp", "udp". This parameter accepts one or more values in the format of params[rules_in][0][action]=tcp, params[rules_in][1][action]=udp.Example: tcp
params[rules_in][0][src_ip]stringThe source IP address for this inbound rule. This can either be a standalone IP or CIDR range. This parameter accepts one or more values in the format of params[rules_in][0][src_ip]=127.0.0.1, params[rules_in][1][src_ip]=127.0.0.2/24.Example: 127.0.0.1
params[rules_in][0][dest_port]integerThe destination port for this inbound rule. This parameter accepts one or more values in the format of params[rules_in][0][dest_port]=22, params[rules_in][1][dest_port]=443.Example: 22
params[rules_out][0][enabled]booleanWhether this outbound rule is enabled or not. This parameter accepts one or more values in the format of params[rules_out][0][enabled]=1, params[rules_out][1][enabled]=1.Example: 1
params[rules_out][0][action]enum[ACCEPT, DROP, REJECT]The action for this outbound rule. The following values are accepted: "ACCEPT", "DROP", "REJECT". This parameter accepts one or more values in the format of params[rules_out][0][action]=DROP, params[rules_out][1][action]=ACCEPT.Example: ACCEPT
params[rules_out][0][protocol]enum[tcp, udp]The protocol for this outbound rule. The following values are accepted: "tcp", "udp". This parameter accepts one or more values in the format of params[rules_out][0][action]=tcp, params[rules_out][1][action]=udp.Example: tcp
params[rules_out][0][dest_ip]stringThe destination IP address for this outbound rule. This can either be a standalone IP or CIDR range. This parameter accepts one or more values in the format of params[rules_out][0][dest_ip]=127.0.0.1, params[rules_out][1][dest_ip]=127.0.0.2/24.Example: 127.0.0.1
params[rules_out][0][dest_port]integerThe destination port for this outbound rule. This parameter accepts one or more values in the format of params[rules_out][0][dest_port]=22, params[rules_out][1][dest_port]=443.Example: 22

Code Samples

JavaScript PHP Rails Python
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "https://api.sitehost.nz/1.5/server/firewall/security_groups/update.json", false);

var data = new FormData();
data.append("apikey", "your_key_here");
data.append("client_id", "1");
data.append("name", "sgfc40e62092");
data.append("params[label]", "My New Security Group Label");
data.append("params[rules_in][0][enabled]", "1");
data.append("params[rules_in][0][action]", "ACCEPT");
data.append("params[rules_in][0][protocol]", "tcp");
data.append("params[rules_in][0][src_ip]", "127.0.0.1");
data.append("params[rules_in][0][dest_port]", "22");
data.append("params[rules_out][0][enabled]", "1");
data.append("params[rules_out][0][action]", "ACCEPT");
data.append("params[rules_out][0][protocol]", "tcp");
data.append("params[rules_out][0][dest_ip]", "127.0.0.1");
data.append("params[rules_out][0][dest_port]", "22");

xmlHttp.send(data);

var response = xmlHttp.responseText;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sitehost.nz/1.5/server/firewall/security_groups/update.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$body = array(
'apikey' => 'your_key_here',
'client_id' => 1,
'name' => 'sgfc40e62092',
'params[label]' => 'My New Security Group Label',
'params[rules_in][0][enabled]' => '1',
'params[rules_in][0][action]' => 'ACCEPT',
'params[rules_in][0][protocol]' => 'tcp',
'params[rules_in][0][src_ip]' => '127.0.0.1',
'params[rules_in][0][dest_port]' => 22,
'params[rules_out][0][enabled]' => '1',
'params[rules_out][0][action]' => 'ACCEPT',
'params[rules_out][0][protocol]' => 'tcp',
'params[rules_out][0][dest_ip]' => '127.0.0.1',
'params[rules_out][0][dest_port]' => 22,
);
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.5/server/firewall/security_groups/update.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,
"name" => "sgfc40e62092",
"params[label]" => "My New Security Group Label",
"params[rules_in][0][enabled]" => "1",
"params[rules_in][0][action]" => "ACCEPT",
"params[rules_in][0][protocol]" => "tcp",
"params[rules_in][0][src_ip]" => "127.0.0.1",
"params[rules_in][0][dest_port]" => 22,
"params[rules_out][0][enabled]" => "1",
"params[rules_out][0][action]" => "ACCEPT",
"params[rules_out][0][protocol]" => "tcp",
"params[rules_out][0][dest_ip]" => "127.0.0.1",
"params[rules_out][0][dest_port]" => 22,
}
request.set_form_data(body)

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

uri = 'https://api.sitehost.nz/1.5/server/firewall/security_groups/update.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['name'] = 'sgfc40e62092'
body['params[label]'] = 'My New Security Group Label'
body['params[rules_in][0][enabled]'] = '1'
body['params[rules_in][0][action]'] = 'ACCEPT'
body['params[rules_in][0][protocol]'] = 'tcp'
body['params[rules_in][0][src_ip]'] = '127.0.0.1'
body['params[rules_in][0][dest_port]'] = 22
body['params[rules_out][0][enabled]'] = '1'
body['params[rules_out][0][action]'] = 'ACCEPT'
body['params[rules_out][0][protocol]'] = 'tcp'
body['params[rules_out][0][dest_ip]'] = '127.0.0.1'
body['params[rules_out][0][dest_port]'] = 22

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

Response

200:

application/json
{
  "return": {
    "job": {
      "type": "scheduler",
      "id": 26864647
    }
  },
  "msg": "Successful",
  "status": true
}