Question

Unable to create droplets using v2 APO

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

Subscribe
Share

Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

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"