/cloud/db/grant/add
POST https://api.sitehost.nz/1.0/cloud/db/grant/add.json
Adds grants to an existing database user.
Form Parameters
Parameter | Type | Required | Description |
client_id | integer | Yes | The ID for the client that the database user belongs to.Example: 1 |
server_name | string | Yes | The server that the database user belongs to.Example: ch-servername |
database | string | Yes | The name of the database to associate the grants with.Example: dbname |
username | string | Yes | The username of the database user to create the grants for.Example: dbuser |
grants[] | string | Yes | The grants to give the user. This parameter accepts one or more values in the format of grants[]=x, grants[]=y.Example: select |
Code Samples
JavaScript PHP Rails Pythonvar xmlHttp = new XMLHttpRequest();
xmlHttp.open("POST", "https://api.sitehost.nz/1.0/cloud/db/grant/add.json", false);
var data = new FormData();
data.append("apikey", "your_key_here");
data.append("client_id", "1");
data.append("server_name", "ch-servername");
data.append("database", "dbname");
data.append("username", "dbuser");
data.append("grants[]", "select");
xmlHttp.send(data);
var response = xmlHttp.responseText;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sitehost.nz/1.0/cloud/db/grant/add.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
$body = array(
'apikey' => 'your_key_here',
'client_id' => 1,
'server_name' => 'ch-servername',
'database' => 'dbname',
'username' => 'dbuser',
'grants[]' => 'select',
);
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.0/cloud/db/grant/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_name" => "ch-servername",
"database" => "dbname",
"username" => "dbuser",
"grants[]" => "select",
}
request.set_form_data(body)
response = http.request(request)
import requests
from collections import OrderedDict
uri = 'https://api.sitehost.nz/1.0/cloud/db/grant/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_name'] = 'ch-servername'
body['database'] = 'dbname'
body['username'] = 'dbuser'
body['grants[]'] = 'select'
response = requests.post(uri, data=body)
Response
200:application/json
{
"return": {
"job_id": "3433562"
},
"msg": "Successful",
"status": true,
"time": 29.92
}
"return": {
"job_id": "3433562"
},
"msg": "Successful",
"status": true,
"time": 29.92
}