Get a list of all available images in the DigitalOcean v2 API

I frequently need to check the slug or id of a particular Droplet image (or in AWS parlance, an AMI) that I can use to launch new DigitalOcean droplets via Ansible. And seeing as tonight I had to search for 'how to get a list of all DigitalOcean images' about the hundredth time, I figured I'd publish this in a blog post so I can find it more easily in the future.

Without further ado:

curl -X GET --silent "" -H "Authorization: Bearer $DO_API_TOKEN"

This assumes you have exported a valid $DO_API_TOKEN previously. If not, just paste your DigitalOcean API token in place of $DO_API_TOKEN, and then run the command.

It dumps out a ton of JSON, so you can either paste it through something like, or try reading it in all it's unformatted glory. And if the latter, are you a robot?

Bonus trick: If you're on a Mac, you can add | pbcopy to the end of that command to have the output stuck into your clipboard, for easy pasting. Or no matter where you are, if you have jq installed, you can add | jq '.' to the end to get it pretty-printed in your console.


doctl, the DigitalOcean command line client, is also useful for this. You can list all images with:

doctl compute image ls

You can also filter the results in a few ways. For instance, if all I want are the names and IDs for my own snapshots, I can use:

doctl compute image list-user --format ID,Name

You might also want to take a look at jq . You can pipe the curl response from the API to it in order to pretty print and/or filter JSON right on the command line.

Thanks. This was exactly what I needed.

Also, by throwing a | grep --color -E "$os_i_am_looking_for" on the end of the command, I don't need to run it through a parser to get the relevant info.

I swear I'm not a robot. :-P