-
-
Save LordRalex/2e90fc4d8f7544de4d42f9fc63ef8003 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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