I wrote a basic API script in PHP using cURL - and successfully used its version on another API, this one is specifically designed to handle DNS management of a domain on DigitalOcean - and I can’t send the data?
Prelude ...
I understand that there is an accessible PHP library, I am not behind something full-featured or bloated dependencies - just something small to use locally , and first of all, to help me understand how the RESTful API works in practice a little better - educational program
Violation Code ...
function basic_api_handle($key, $method, $URI, $data) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer '.$key,
'Content-Type: application/json')
);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($ch, CURLOPT_URL, $URI);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$result = curl_exec($ch);
if($result === false) error_log("API ERROR: Connection failure: $URI", 0);
curl_close($ch);
return json_decode($result, true);
}
var_dump(basic_api_handle($api_key, 'POST', 'https://api.digitalocean.com/v2/domains', array('name' => 'my-domain.tld', 'ip_address' => '1.2.3.4')));
GET, , , , / ... "unprocessable_entity" "Name " - ( ), , ?
...
json (. ), json, url json , .
DigitalOcean API ( ), ( - ).
cURL .., API .
, , , , POST PUT . , API , , , - ?
!:)
Edit:
API Digital Ocean (, https://github.com/ledfusion/php-rest-curl) - - API - API?