Cloudshare Rest api allows to perform number of actions using web UI application. Client will do create the environments and check the status of its environments and take snapshop of them.
Let me explain how to get connect or authenticate with Cloudshare rest api in PHP:
Request Url: https://use.cloudshare.com/API/v2
Parameter Required for api request are:
– ver :- Its the version of api for example v2 and v3
– resource :- api function name
– UserApiId :- Assigned unique id by cloudshare. This will use in each api request.
– token :- use any random string of 10 characters. Combination must be include (a-z, A-Z, 0-9)
– timestamp :- use time in seconds. Use time(); php function to get it.
– signature: – HMAC signature. Use below paatern to create it.
– param -: This is optional parameter for each request.
Use below code to generate the random number :
1 2 3 4 5 6 7 8 |
////// Generate random number /////////////// function randomize(){ $chars = array_merge(range("a","z"),range("A","Z"),range("0","9")); shuffle($chars); return implode('',array_slice($chars,0,10)); } echo "token-".$newtoken = randomize(); |
To create signature string use below code:
1 2 3 |
$sign = 'API KEy HerelistenvironmentstimestampTIMESTAMP VALUEtokenTOKEN VALUEuserapiidUNIQUE USER ID'; $sign_value = sha1($sign, false); |
See this example to get List Environment of cloudshare account via rest api call.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$api_url = 'https://use.cloudshare.com/API/v2/Env/ListEnvironments?UserApiId=USER ID HERE&token=RANDOM TOKEN×tamp=TIMESTAMP VALUE&HMAC=SHA1 SIGNATURE VALUE'; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $api_url ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array ('Accept: application/json', 'Content-Length: 0') ); curl_setopt( $ch, CURLOPT_VERBOSE, 0 ); curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET'); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); $response = curl_exec( $ch ); $result31 = json_decode($response); echo "<pre>"; print_r($result31); |
After following all the above step this script will show you List of Environments of client Cloudshare account.