RACKCORP REST API
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 allowallows your code makesto HTTPmake requestHTTPS requests to our endservices and be authorized to get data fromfor your services. We will explain here how you add this API Key in your code.
URL toTo create yourAPI keycredentials, goto ADMINISTRATION -> API in our portal:portal. URL: https://portal.rackcorp.com/index.php?cmd=api
Them,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 is the URL which follows the patterspatterns below:
version: v2.7
main URL: https://api.rackcorp.net/api
object data: customers | dcs | network | api | dns | devices
URL format: https://api.rackcorp.net/api/+version+/object data/+ID item
Example GET all data: https://api.rackcorp.net/api/v2.7/devices
Example GET one Item: https://api.rackcorp.net/api/v2.7/devices/1
Bellow we addis 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,code. beBe careful when useusing 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:
In the sample bellow we add a dummy API KEY and API SECRET. Please, change this data accordingly with your data
<?php
// Simple example to get a list of all datacenters
$version = 'v2.7';
$url = "https://api.rackcorp.net/api/". $version . "/customers"dc";
$query = ["cmd"=>"dc.getall"];
$query['APIUUID'] = ""; // No authetnication required for getting datacenter list
$query['APISECRET'] = "";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($query));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
if($response) {
return json_decode($response, true);
}
return false;
?>
PYTHON:
import json
import logging
import 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+'/'+customersdc
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)
As you can see in both example,examples, the logic to connect through our API is quite simple. You just need the URL, the APIUUID and APISECRET beenas part of the object or array,array andthat gets passed to the variables which you pass through the API to build the query in out back-end.API.
Hope you get the basic understading how to use our REST API functionalities. BellowBelow you can find links with more advanced docs to use our API. Also, the complete list of REST API services (urls) explaining the query data and the expected response data for each situation.
REST API GibHub Docs:
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 useused for tests.
Link: https://app.swaggerhub.com/apis/RackCorp/Rackcorp-REST-API/2.7