Skip to content

Instantly share code, notes, and snippets.

@LordRalex
Created July 11, 2018 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LordRalex/2e90fc4d8f7544de4d42f9fc63ef8003 to your computer and use it in GitHub Desktop.
Save LordRalex/2e90fc4d8f7544de4d42f9fc63ef8003 to your computer and use it in GitHub Desktop.
<?php
$BASE_URL = '-----------------';
$CLIENT_ID = '-----------';
$CLIENT_SECRET = '----------------------';
$SERVER_ID = '------------------';
function getAccessToken()
{
global $BASE_URL;
global $CLIENT_ID;
global $CLIENT_SECRET;
$ch = curl_init($BASE_URL . '/oauth2/token/request');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials&client_id=' . $CLIENT_ID . '&client_secret=' . $CLIENT_SECRET);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
$data = json_decode($result);
return $data->access_token;
}
$token = getAccessToken();
//now, do what you want. Let's stop a server
$ch = curl_init($BASE_URL . '/daemon/server/' . $SERVER_ID . '/stop');
$header = array();
$header[] = "Authorization: Bearer " . $token;
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_exec($ch);
curl_close($ch);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment