How should I send ssh_keys when creating a droplet API?

July 2, 2015 1.1k 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"
1 Answer

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.

Have another answer? Share your knowledge.