Hoe de Ikoula API te gebruiken?
fr:Comment utiliser l'API d’Ikoula en:How to use the Ikoula API es:Cómo utilizar la API de Ikoula zh:如何使用Ikoula的API it:Come utilizzare l'API Ikoula
Introductie
Ikoula heeft een API die u toelaat acties uit te voeren op de producten verbonden aan uw klantenrekening. Hier is de URL van de API: https://api.ikoula.com
Documentatie is direct beschikbaar voor elk product.
Uitleg
Om voor de hand liggende veiligheidsredenen, vereist de Ikoula API authenticatie. Deze is gebaseerd op een gebruikersnaam, een wachtwoord en een handtekening:
- De identifier is het e-mail adres dat wordt gebruikt om verbinding te maken met uw Ikoula account of met het Extranet. De naam van de parameter om het te verzenden is altijd login ;
- Het paswoord moet gecodeerd worden via een specifieke functie met behulp van een publieke sleutel geleverd door Ikoula crypted_password parameter) en base64_encode ;
- De handtekening wordt gegenereerd volgens de parameters die worden opgegeven bij het aanroepen van de API.
- Deze parameters moeten altijd in GET aan de API worden doorgegeven!
WAARSCHUWING:
Voor uw API tests kunt u bijvoorbeeld een tijdelijke gebruiker gebruiken die speciaal voor deze tests is aangemaakt. Het gebruik van wachtwoord encryptie met de Ikoula publieke sleutel is essentieel in elke productie of niet-korte termijn context.
Indien de API oproepen gebruikt moeten worden via een script of een programma, raden wij U aan om hiervoor een specifieke gebruiker aan te maken in plaats van uw klassieke extranet gebruiker te gebruiken.
Twee mogelijkheden staan tot uw beschikking:
- Maak een sub-gebruiker rechtstreeks aan vanaf de startpagina van uw extranet account ((Zie de WIKI hieronder voor het aanmaken van sub-gebruikers: Hoe maak je een subaccount?).
- Neem contact op met onze support voor het aanmaken van een extranet gebruiker indien nodig.
Vergeet niet hem de rechten te geven op de gewenste diensten.
Encryptiesleutel
De openbare wachtwoord-coderingssleutel is beschikbaar op het volgende adres: https://api.ikoula.com/downloads/Ikoula.API.RSAKeyPub.pem
Wrapper PHP
<?php
// #################################################
// #### ..:: Ikoula Hosting Services ::.. ###
// #### Wrapper for https://api.ikoula.com ###
// #################################################
class IkoulaAPI {
/**
* Email of Ikoula account
* @var string Email account
*/
private static $email = "EMAIL_ACCOUNT_IKOULA";
/**
* Password of Ikoula account
* @var string Password account
*/
private static $password = "PASSWORD_ACCOUNT_IKOULA";
/**
* Ikoula API URI
* @var string Password account
*/
private static $urlApi = "https://api.ikoula.com/";
/** Public key path for encrypt data
* @var string Path of public key
* @see https://api.ikoula.com/downloads/Ikoula.API.RSAKeyPub.pem
*/
private static $publicKeyPath = "/path/to/ikoula/public/key/Ikoula.API.RSAKeyPub.pem";
/** Fonction for request Ikoula API
* @param string $webservice Webservice for data
* @param string $format JSON or XML
* @param string $type HTTP Type (GET/POST)
* @param array $params Params to add for request
*/
public static function requestApi($webservice, $format, $type, $params = [])
{
// Add connexion information
$params['login'] = self::$email;
$params['crypted_password'] = base64_encode(self::opensslEncryptPublic(self::$password));
$params['format'] = $format;
// Fix params to lowercase for generate signature correctly
$params = array_change_key_case($params);
// Generate signature
$signature = self::createSignature($params);
// Add signature for call
$params['signature'] = $signature;
// Curl init
$ch = curl_init();
if($ch)
{
// Create API URI
$url = self::$urlApi.$webservice;
// Add type request
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type);
// If parameters, we encode his
if(is_array($params) && count($params) > 0)
$params_str = http_build_query($params);
// If we use post, fix params
if(strcasecmp("POST", $type) == 0)
{
// Fix POST data
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS, $params_str);
}
else
$url .= (strpos($url,'?') === false ? '?' : '&').$params_str;
// Create curl info
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, false);
// Exec request
$data = curl_exec($ch);
// Close curl object
curl_close($ch);
// Return response
return($data);
}
return null;
}
/** Create signature with params
* @param array $params Params to add for request
* @return string Signature encoded
*/
private static function createSignature($params = [])
{
// Signature to send
$signature = null;
// Verify parameters
if (count($params) > 0)
{
// Sort params
ksort($params);
// Encode params
$query = http_build_query($params);
// Encode "plus "+"
$query = str_replace("+", "%20", $query);
// Transform in lowercase
$query = strtolower($query);
$public_key = "";
// Verify if key file is present
if (file_exists(self::$publicKeyPath))
{
// Get public key
$public_key = trim(
str_replace(
array("\n", '-----BEGIN PUBLIC KEY-----','-----END PUBLIC KEY-----'),
array('', '', ''),
file_get_contents(self::$publicKeyPath)
)
);
}
// SHA1 hash
$hash = hash_hmac("SHA1", $query, $public_key, true);
// base64 encode
$signature = base64_encode($hash);
}
return $signature;
}
/** Fonction for crypt Ikoula password
* @param string $password Ikoula account password
* @return mixed Ikoula password encrypted, null if error
*/
private static function opensslEncryptPublic($password)
{
// Verify if key file exist
if(file_exists(self::$publicKeyPath))
{
// Verify if password is not empty
if(!empty($password))
{
// Get file content
$publicKey = openssl_pkey_get_public('file://'.realpath(self::$publicKeyPath));
// If we get file content without error
if ($publicKey !== FALSE)
{
// Encrypt password
if(openssl_public_encrypt($password, $crypted, $publicKey) === TRUE)
return $crypted;
else
return NULL;
}
else
return NULL;
}
else
return NULL;
}
else
return NULL;
}
}
Exemples d'utilisation
// Fix JSON header
header("Content-type: application/json");
// Get Exch schema for prestation
echo IkoulaAPI::requestApi("wsexch/schema-subscr", "json", "GET", ['subscr_id' => 999999999]);
// Get Flex VM for Ikoula Account
echo IkoulaAPI::requestApi("wsflex/list", "json", "GET", []);
// Get Flex VM for Ikoula Account
echo IkoulaAPI::requestApi("wsflex/list", "json", "GET", []);
// Get Platform list
echo IkoulaAPI::requestApi("wsplatform/list", "json", "GET", []);
// Get Platform dossiers
echo IkoulaAPI::requestApi("wsplatform/dossiers", "json", "GET", ['platform_id' => 999999999]);
// Get Billing conso for CloudStack prestation
echo IkoulaAPI::requestApi("wscs/conso-for-billing", "json", "GET", ['subscr_id' => '999999999', 'billing_id' => '1']);
// Reboot server
echo IkoulaAPI::requestApi("wsds/reboot-apc-request", "json", "GET", ['server_ip' => 'XXX.XXX.XXX.XXX', 'tempo' => '3']);
Functie toevoegen
Neem in het geval van een functieverzoek contact op met de technische ondersteuning.