Create a droplet with PHP API v2

Posted October 4, 2014 5.6k views


I am trying to create an droplet with php and I have read the on how it could be achieved but I haven’t really got it working yet.

My PHP code is as following:

$data = 'name=TestDroplet&region=ams3&size=512mb&image=449676322';
$create_droplet = curl_init();

        CURLOPT_POST => 0,
        CURLOPT_URL => '',
        CURLOPT_HTTPHEADERS => array(
            'Authorization: Bearer ACCESS_TOKEN',
            'Content-Type: application/json',
            'Content-Length: ' . strlen($data)
        CURLOPT_POSTFIELDS => $data

$create = curl_exec($create_droplet);

echo '<pre>';
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?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

CURLOPT_HTTPHEADERS should be CURLOPT_HTTPHEADER, see PHP: curl_setopt - Manual for the list of available options.

  • Thanks kamaln7. That helped.

    I get an error saying You specified an invalid image for Droplet creation..
    I tried the image number in the document but same error. I changed it to some random number and still same error.

    What does it mean?

I have solved it!