Hi,
I am trying to create an droplet with php and I have read the https://developers.digitalocean.com/v2/#create-a-new-droplet on how it could be achieved but I haven’t really got it working yet.
My PHP code is as following:
$data = 'name=TestDroplet®ion=ams3&size=512mb&image=449676322';
$create_droplet = curl_init();
curl_setopt_array(
$create_droplet,
array(
CURLOPT_USERAGENT => "METESTING",
CURLOPT_POST => 0,
CURLOPT_URL => 'https://api.digitalocean.com/v2/droplets',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADERS => array(
'Authorization: Bearer ACCESS_TOKEN',
'Content-Type: application/json',
'Content-Length: ' . strlen($data)
),
CURLOPT_POSTFIELDS => $data
)
);
$create = curl_exec($create_droplet);
curl_close($create);
echo '<pre>';
print_r($create);
echo '</pre>';
I get this error --> {“id”:“unauthorized”,“message”:“Unable to authenticate you.”}.
I have checked the ACCESS_TOKEN and it is correct. I have even regenerated it several times and I have it on read, write support.
Does anyone know what I might be missing?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
CURLOPT_HTTPHEADERS should be CURLOPT_HTTPHEADER, see PHP: curl_setopt - Manual for the list of available options.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.