Unable to create droplets using v2 APO

March 27, 2018 411 views
API Ubuntu

I am unable to create any droplets using the REST api (via curl). Based on the documentation[1] I only need to specify the name, region, size and image. No matter what I use, I cannot seem to create using my token which has write ability. I tried the name and id returned by v2/images API but I am not able to get any successful execution. The sample in the v2/droplets documentation uses an image string that is not part of what is returned by the v2/images api.

What I have tried so far:

// first command has the json data based from the web api doc

curl -X GET "https://api.digitalocean.com/v2/droplets" -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" -d '{"name":"example.com","region":"nyc3","size":"s-1vcpu-1gb","image":"ubuntu-16-04- x64","ssh_keys":null,"backups":false,"ipv6":true,"user_data":null,"private_networking":null,"volumes": null,"tags":["web"]}'

curl -X GET "https://api.digitalocean.com/v2/droplets" -H "Authorization: Bearer $TOKEN" -d'{"name":"pytut-ubuntu64","region":"fra1", "size": "s-1vcpu-1gb", "image": "ubuntu-16-04-x64"}' -H "Content-Type: application/json"

// image id and string is from the results of v2/images. This does not have a slug.

curl -X GET "https://api.digitalocean.com/v2/droplets" -H "Authorization: Bearer $TOKEN" -d'{"name":"pytut-ubuntu64","region":"fra1", "size": "s-1vcpu-1gb", "image": 21669205}' -H "Content-Type: application/json"

curl -X GET "https://api.digitalocean.com/v2/droplets" -H "Authorization: Bearer $TOKEN" -d'{"name":"pytut-ubuntu64","region":"fra1", "size": "s-1vcpu-1gb", "image": "16.04.1 x64"}' -H "Content-Type: application/json"


I have also tried nyc3 as the location all i am getting is

{"droplets":[],"links":{},"meta":{"total":0}}

Again, I can create droplets using the browser, and my token has both read and write scope. I would appreciate if somebody can point me on where my invocation contained an error.

[1] https://developers.digitalocean.com/documentation/v2/#create-a-new-droplet

1 Answer
asb MOD March 27, 2018
Accepted Answer

Sending a GET request to api.digitalocean.com/v2/droplets will list your Droplets. Instead, to create a Droplet, you need to use a POST request. For example:

curl -X POST -H "Content-Type: application/json" \
    -H "Authorization: Bearer $TOKEN" \
    -d '{"name":"example.com","region":"fra1","size":"s-1vcpu-1gb","image":"ubuntu-16-04-x64"}' \ 
    "https://api.digitalocean.com/v2/droplets" 
Have another answer? Share your knowledge.