PHP

Introduction

					

Getting Started

To access the Tera API, an API key will need to be established. Use the following steps to create an API key for your account:

  1. Login to Tera at https://cp.100tb.com
  2. Open the API Manager by selecting Tools > API.
  3. Select Add Key, provide a description for the key, and click OK.

An API Key will be generated, which will be required to access the Tera API Server. For information regarding the basic usage of the API, take a look at our API Basics section. You may also use the API Explorer as a resource to view all available Tera API operations.

Using the API Explorer

The API Explorer can be used to discover all of the available resources within the Tera API.

To use the API Explorer, an API Key needs to be provided in the api_key textfield at the top-left of the page, If an API Key is not provided, a 400: Missing Authentication error will be returned. By clicking one of the available resources, you can view the operations and appropriate HTTP methods included with that resource. Provide any of the required parameters for a specific operation, then click the Try it out! button to send the request. A response will show, including the following data:

  • Request URL
  • Response Code + Headers
  • Response Body

In most cases, API requests will return encoded JSON (JavaScript Object Notation) data. However there are some API requests that will return raw data, such as PNG image data for the bandwidth graph operations, or raw html formatted invoice. These special cases will be noted in the Implementation notes for that specific resource operation.

						
                        
					

API Basics

API requests can be made by using curl or any programming language that supports HTTP requests. All requests should be made to the following endpoint: https://cp.100tb.com/rest-api/

Authentication

Every request URL will require the api_key parameter. If the api_key parameter is not provided, then a 400: Missing Authentication error will be returned.

Examples

Every method request will be accompanied by an example block of code to the right of the method call. If you look to the right side pane you will see an example call using get and curl. However each method call will be formatted in PHP with the use of Tera's PHP API Client.

						
#How to use cURL via PHP
#GET request via PHP


$request_url = "https://cp.100tb.com/rest-api/servers.json?api_key=PLACE_KEY_HERE";

$ch = curl_init($request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$result = array(
'response_body' => curl_exec($ch),
'info' => curl_getinfo($ch),
);

curl_close($ch);
print_r($result);
                        
					

API Client

100TB has invested resources into providing clients with a powerful and yet simple to use PHP API Client. Similar to the API Explorer, the PHP API client requires the use of an api_key.
(Follow the steps outlined here to obtain your key now)

By utilizing the PHP API client, you can simply copy and paste all the example code provided for each method call. If you wish to utilize it, you may do so by downloading it from here: Download

						
                        
					

Billing

					

GET /billing/invoices.json

Implementation Notes
Get list of invoices
Parameters
Name Type Required Description
start integer No Start date (UNIX timestamp). Required if custom date range is needed, otherwise optional.
end integer No End date (UNIX timestamp). If not provided, will use today as end date.
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'start' => 'integer',
		'end' => 'integer'
);

try {
    $response = $teraApi->get('/billing/invoices.json',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

[{'id':2004321,'generated':'2015-01-29','due':'2015-01-31','amount':47.50,'status':'Unpaid'}]

GET /billing/invoices.json/{invoice}

Implementation Notes
Get details for an invoice (Returns raw HTML formatted invoice)
Parameters
Name Type Required Description
invoice integer Yes Invoice ID.
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'invoice' => 'integer'
);

try {
    $response = $teraApi->get('/billing/invoices.json/{invoice}',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

GET /billing/services.json

Implementation Notes
Get list of services
Parameters
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    //empty
);

try {
    $response = $teraApi->get('/billing/services.json',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

[{'id':12345,'description':'My first server','start_date':'01-01-2015','price':130.00,'addons':[{'id':54321,'description':'R1Soft Agent','start_date':'01-07-2015','price':8.00}]}]

GET /billing/services.json/{service}

Implementation Notes
Get details for a service
Parameters
Name Type Required Description
service integer Yes Service ID.
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'service' => 'integer'
);

try {
    $response = $teraApi->get('/billing/services.json/{service}',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

{'id':12345,'description':'My first server','start_date':'01-01-2015','price':130.00,'addons':[{'id':54321,'description':'R1Soft Agent','start_date':'01-07-2015','price':8.00}]}

Ip

					

GET /ip.json/{server}

Implementation Notes
Get IPv4 addresses that belong to a server
Parameters
Name Type Required Description
server integer Yes Server ID.
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'server' => 'integer'
);

try {
    $response = $teraApi->get('/ip.json/{server}',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

[{'ip':'10.0.10.1','ptr':'test.example.com'},{'ip':'192.168.1.1','ptr':'notreal.example.com'}]

PUT /ip.json/{server}/{ip}

Implementation Notes
Set an IPv4 address PTR record
Parameters
Name Type Required Description
server integer Yes Server ID.
ip string Yes IP address to set (with periods).
ptr string Yes hostaname to resolve IP address to.
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'server' => 'integer',
		'ip' => 'string',
		'ptr' => 'string'
);

try {
    $response = $teraApi->put('/ip.json/{server}/{ip}',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

'boolean'

Servers

					

GET /servers.json

Implementation Notes
Get a list of all servers assigned to account
Parameters
Name Type Required Description
limit integer No Only fetch $limit records
offset integer No Fetch records starting at $offset
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'limit' => 'integer',
		'offset' => 'integer'
);

try {
    $response = $teraApi->get('/servers.json',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

[{'id':12345,'fqdn':'reseller.example.com','public_ip':'255.255.255.255','private_ip':'10.10.0.1','unlimited':false,'pet_name':'my first server'}]

GET /servers.json/{server}

Implementation Notes
Get full server profile
Parameters
Name Type Required Description
server integer Yes Server ID
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'server' => 'integer'
);

try {
    $response = $teraApi->get('/servers.json/{server}',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

[{'id':12345,'fqdn':'reseller.example.com','public_ip':'255.255.255.255','private_ip':'10.10.0.1','unlimited':false,'pet_name':'my first server','ips':{'ip':'255.255.255.255','ptr':'reversedns.reseller.example.com'},'info':{'login_details':{'username':'myuser','password':'mypassword'},'os':'Ubuntu','datacenter':'Seattle / Server Room 4','active_transactions':'','notes':'','monitoring':''}}]

GET /servers.json/{server}/bandwidth

Implementation Notes
Returns raw bandwidth data. The start parameter is required if a custom date range is needed, otherwise it is optional. If a custom date range is provided, the period parameter is ignored and a maximum of 40 date intervals are returned.
Parameters
Name Type Required Description
server integer Yes Server ID
period string No Graph period (daily, weekly, monthly, yearly, billing). Weekly by default
start integer No Start date (UNIX timestamp). Required if custom date range is needed, otherwise optional.
end integer No End date (UNIX timestamp). If not provided, will use today as end date.
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'server' => 'integer',
		'period' => 'string',
		'start' => 'integer',
		'end' => 'integer'
);

try {
    $response = $teraApi->get('/servers.json/{server}/bandwidth',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

GET /servers.json/{server}/bandwidth_graph

Implementation Notes
Returns raw PNG image data of the bandwidth graph. The start parameter is required if a custom date range is needed, otherwise it is optional. If a custom date range is provided, the period parameter is ignored.
Parameters
Name Type Required Description
server integer Yes Server ID
period string No Graph period (daily, weekly, monthly, yearly, billing). Weekly by default
start integer No Start date (UNIX timestamp). Required if custom date range is needed, otherwise optional.
end integer No End date (UNIX timestamp). If not provided, will use today as end date.
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'server' => 'integer',
		'period' => 'string',
		'start' => 'integer',
		'end' => 'integer'
);

try {
    $response = $teraApi->get('/servers.json/{server}/bandwidth_graph',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

'graph.png'

POST /servers.json/{server}/reboot

Implementation Notes
Gracefully reboot a server
Parameters
Name Type Required Description
server integer Yes Server ID
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'server' => 'integer'
);

try {
    $response = $teraApi->post('/servers.json/{server}/reboot',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

'Server is rebooting'

POST /servers.json/{server}/rescue

Implementation Notes
Rescue mode provides the ability to bring a server online to troubleshoot system problems that would normally only be resolved by an OS Reload. When the rescue occurs, the server will shutdown and reboot on to the public network with the same IP's assigned to the server to allow for remote connections. The server will be offline for approximately 10 minutes while the rescue is in progress. The server login credentials will be the same as what are listed on the server's profile.
Parameters
Name Type Required Description
server integer Yes Server ID
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'server' => 'integer'
);

try {
    $response = $teraApi->post('/servers.json/{server}/rescue',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

'Server is rebooting to rescue mode'

POST /servers.json/{server}/enable

Implementation Notes
Enables a server's public network port. The maximum allowed speed will be set on the network port if the speed parameter is not provided.
Parameters
Name Type Required Description
server integer Yes Server ID
speed integer No Speed to set the network port to
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'server' => 'integer',
		'speed' => 'integer'
);

try {
    $response = $teraApi->post('/servers.json/{server}/enable',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

'Public network port speed setting of $speed was successful'

POST /servers.json/{server}/disable

Implementation Notes
Disable public network port on a server.
Parameters
Name Type Required Description
server integer Yes Server ID
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    'server' => 'integer'
);

try {
    $response = $teraApi->post('/servers.json/{server}/disable',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

'Public network port speed setting of $speed was successful'

Updates

					

GET /updates.json

Implementation Notes
Get a list of active status updates
Parameters
Sandbox
Parameters
						
						
$teraApi = new TeraAPI('PLACE_KEY_HERE');

$params = array(
    //empty
);

try {
    $response = $teraApi->get('/updates.json',$params);
    print_r($response);
} catch(apiException $e) {
    print $e->getMessage();
}
						
						
HTTP 200 OK

[{'id':'8','title':'DDOS','dc':'London','posted':'2015-01-29','status':'Our network engineers are working on mitigating the network traffic being caused by the DOS attack at the London DC','date':'2015-01-29 14:38:09'}]