Skip to main content

RACKCORP REST API EXAMPLES

Rackcorp has migrated many of its functionalities to work with REST API architecture to modernize and make easy the process to get data through HTTP protocol. Every month we are adding new services through REST API. It is important you follow us to get the last updates and the last version of our API.

API Information:

Current Version: v2.7

API URL: https://www.rackcorp.net/api/v2.7

Before you start to create any code or connect through our API, you need to create an API Key access which allows your code to make HTTPS requests to our services and be authorized to get data for your services. We will explain here how you add this API Key in your code.

To create API credentials, goto ADMINISTRATION -> API in our portal.  URL: https://portal.rackcorp.com/index.php?cmd=api

Then, you click ADD, type a name for this new Key and a secret ( password ) and SAVE.

API Standards:

As described in our article REST API Architecture and Standards, there is no definitive standard patterns that all engineers/devs should follow to create REST API for their app. In Rackcorp we keep things simple. The main structure for our REST API follows the patterns below:

version: v2.7

main URL: https://api.rackcorp.net/api

object data: customers | dc | network | api | dns | device

URL format: https://api.rackcorp.net/api/+version+/object data/+ID item

Example GET all data: https://api.rackcorp.net/api/v2.7/device

Example GET one Item: https://api.rackcorp.net/api/v2.7/device/1 

Bellow is some example code which you can use as example to implement your first REST API connection to our platform:

We strongly recommend that you only make REST API calls from your back-end code.  Be careful when using javascript code to call a REST API url. Never add your credentials in front-end code.  Speak to our team if unsure.

In this simple introduction to code REST API, we will use PHP and PYTHON programming language.

PHP:

InSimple theserver sample bellow we add a dummy API KEY and API SECRET. Please, change this data accordingly with your datacreation:

<?php
//function SimplerackcorpAPI($action, example$request) to{
get a list of all datacenters
$versionrequest["APIUUID"] = 'v2.7'"";
$urlrequest["APISECRET"] = "";
$request["cmd"] = $action;

$curl = curl_init("https://api.rackcorp.net/api/". $version . "/dc"rest/v2.7/json.php");
curl_setopt($querycurl, =CURLOPT_POST, ["cmd"=>"dc.getall"]true);
$query['APIUUID'] = ""; // No authetnication required for getting datacenter list
$query['APISECRET'] = "";


$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($query)request));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($curl);
curl_close($curl);
if( if ( !$response)response ) {
return Array("code" => "FAULT", "message" => "API Error");
}
return json_decode($response, true);
}

return$customerID false;= 1000; // Change this to your customer ID (available in portal under ADMINISTRATION -> MY DETAILS)
// locations are defined here: https://wiki.rackcorp.com/books/help-and-support-en/page/rackcorp-datacenter-locations-and-codes

$neworder = Array(
"productCode" => "SERVER_VIRTUAL_PERFORMANCE_AU",
"customerId" => $customerID,
"quantity" => 1,
"productDetails" => Array(
"hostname" => "testrouter01",
"cpu" => 4,
"memoryGB" => 4,
"trafficGB" => 100,
"nics" => Array(
Array(
"name" => "public",
"speed" -> 1000,
"ipv4" => 1,
)
),
"storage" => Array(
Array(
"name" => "MAIN",
"sizeGB" => 30,
"type" => "SSD",
"order" => 1
)
),
"credentials" => Array(
Array(
"username" => "root",
"password" => "DUGHsUIYGUI312TEST"
)
),
"location" => "RC-AU-GLOBESW1",
"timezone" => "UTC",
"install" => Array (
"operatingSystem" => "UBUNTU20.04_64",
"template" => "standard",
"postInstallScript" => ""
)
)
);
// Lodge the order (this just locks pricing in for up to 72 hours but doesnt actually create any resources)
$response = rackcorpAPI("order.create", $neworder);
var_dump($response);

// You can look up the order if you want:
$neworder = Array ("orderId" => $response["orderId"]);
$response = rackcorpAPI("order.getall", $neworder);
var_dump($response);

// Then confirm the order to start provisioning:
$neworder = Array ("orderId" => $response["orderId"]);
$response = rackcorpAPI("order.confirm", $neworder);
var_dump($response);

?>

PYTHON:Starting a server using cloud-init:

import

After json
importcreating logging
importa sys
import os
import glob
import re
from bson import json_util
from flask.helpers import make_response
from flask import request, jsonify

version = 'v2.7'
apiurl = 'https://api.rackcorp.net/api'+version+'/'+dc
setheaders = {
'content-type': 'application/json',
'User-Agent': 'Mozilla',
'jwt': jwt
}

data = {}
data['APIUUID'] = ''
data['APISECRET'] = ''

apiresp = None
apiresp = requests.get(self.apiurl+'/sessions/logout',data=self.rcdata,headers=setheaders)

Asserver, you can seealso in both examples, the logicchoose to connectstart throughit ourusing API is quite simple. You just need the URL, the APIUUID and APISECRET as part of the object or array that gets passed to the API.

Below you can find linkscloud-init with moreyour advancedown docscustom tocode:

use
$cloudInitStartupData our= API. Array(
Also,"cloudInit" the=> completeArray(
list"volumeName" of=> REST"config-2",
API"userData" services=> "#cloud-config
ssh_pwauth: True
users:
- default
- name: user1
groups: sudo
shell: /bin/bash
sudo: ['ALL=(ALL) NOPASSWD:ALL']
plain_text_passwd: testtest888
lock_passwd: false
",
"metaData" => "instance-id: ServerTest9999
local-hostname: MyServerHostname9999
"
)
);
$serverIDToStart = 9999;
$tx = Array (urls)"objId"=>$serverIDToStart, explaining"objType"=>"DEVICE", the"type"=>"STARTUP", query"data"=>json_encode($cloudInitStartupData));

// dataSee andearlier the expected response dataexample for eachrackcorpAPI situation.

function
$response
REST= APIrackcorpAPI("rctransaction.create", GibHub Docs:
$tx);
var_dump($response);
?>

Link: https://github.com/RackCorpCloud/rackcorp-api/wiki/RACKCORP-REST-API

Swagger RACKCORP REST API:

Swagger is a suite of API developer tools from SmartBear Software and a former specification upon which the OpenAPI Specification is based. This platform displays in simple layout all REST API functions allowing you visualize what your code should expect as response for each call (GET, PUT, PUSH, DELETE).

You can see through this platform the schema for each function and also, the expected JSON format response. You can also make tests to connect through your services in our servers using your real APIUUID and APISECRET.

It is good for testing staging environments and make sure that your call will receive exactly what your code expects.

Dont forget to select which url path API you wanna use for tests. In Swagger page you can see in Server three options. The first one is a swagger mocking URL which is not for tests. The second one is the RACKCORP Production REST API Core (please be careful to use this URL ). The third one is the RACKCORP Staging REST API which should be used for tests.

Link: https://app.swaggerhub.com/apis/RackCorp/Rackcorp-REST-API/2.7