How should I send ssh_keys when creating a droplet API?

July 2, 2015 3.3k views
API DigitalOcean

I was trying to create a droplet trought API, I created some droplets succesfully without ssh_keys fields, but when I try to use this field I got this error: “are invalid key identifiers for Droplet creation”.
I created the key using digital ocean tutorial, after that I got the fingerprint using this command :

ssh-keygen -lf id_rsa.pub

Then I added this fingerprint value as the first argument of a array of ssh_keys field. I was using nodejs in those tests.

I also try to use curl to test this web service, without ssh_keys everything works, but when I add that field I get the same error.

This is my curl command (token and fingerprint modified for this example).

curl -X POST -H 'Content-Type: application/json' -H 'Authorization: Bearer 701d61eabc12d90cf0efd7a57157f2b998a59455873e5db6d2c062d6234d6b37' -d '{"name":"example.com","region":"nyc3","size":"512mb","image":"ubuntu-14-04-x64","ssh_keys": [ "b4:2a:c9:ec:41:ua:a0:yt:95:5e:6b:2e:aa:a0:ef:aa" ] }' "https://api.digitalocean.com/v2/droplets"
2 Answers

The ssh_keys field when creating a droplet expects an array of ssh key IDs. You first need to add your key to DigitalOcean via this endpoint: https://developers.digitalocean.com/documentation/v2/#create-a-new-key

Then you can use that ID to identify the key.

hi @ryanpq. do you have any actual examples for uploading ssh keys besides pointing to the API docs? I’ve poured through the docs and have experienced issues with this as well. Maybe there is a bug on digital ocean’s end, where they think that the uploaded ssh_keys arent an array, when really they are? Here’s my similar issue. I’ve been banging my head on this for a while, because it appears as if it is very obviously an array… https://www.digitalocean.com/community/questions/the-provided-ssh_keys-value-must-be-an-array

Have another answer? Share your knowledge.