Skip to content

Instantly share code, notes, and snippets.

@mr119
Created April 20, 2021 13:12
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 mr119/0e746243957522ae27372dac47590eb1 to your computer and use it in GitHub Desktop.
Save mr119/0e746243957522ae27372dac47590eb1 to your computer and use it in GitHub Desktop.
OnApp API Example on CloudCone Private Clouds
<?php
# Set these values based on your login details
$cloud_url = 'https://cloudcone.cloud.url.com';
$username = 'user';
$password = 'password';
function APICall($path, $type, $post_params = array())
{
global $cloud_url, $username, $password;
$ch = curl_init($cloud_url.$path);
if ($type === 'DELETE') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
} else if ($type === 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_params));
} else if ($type === 'PUT') {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_params));
}
else if($type === 'PATCH')
{
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH');
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($post_params));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Accept: application/json'
));
$return = json_decode(curl_exec($ch), true);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return ['response' => $return, 'http_code' => $httpcode];
}
# Relevent params from doc
$data = [
'dns_record' => [
'name' => '76',
'hostname' => 'ptr.record.com',
'ttl' => '43200',
'type' => 'PTR'
]
];
# Replace :id with zone id, for example 2
var_dump(
APICall(
'/dns_zones/2/records.json',
'POST',
$data
)
);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment