Question

Droplet ID Number to Place in Variable

I can find a droplet id number and other information by …

curl -X GET “https://api.digitalocean.com/droplets/?client_id=XXXXX&api_key=ZZZZZ

But, I want to retrieve just the id number, so it can be added to a variable.

Any help appreciated. Thanks.


Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Before starting with some PHP coding, I was just trying to see if there might be some sort of simple command, unknown to me, to use before figuring out the code. Your responses helped me with the direction to take. Some truncating/parsing of the JSON with strstr and substr got me the droplet id number to assign to a variable.

Thanks again for the help.

If you want to find the droplet ID programmatically, you can get a list of all active droplets with: <pre> curl -X GET “https://api.digitalocean.com/v1/droplets/?client_id=$DO_CLIENT_ID&api_key=$DO_API_KEY” </pre> The results will look like: <pre> { “status”: “OK”, “droplets”: [ { “id”: 100823, “name”: “test222”, “image_id”: 420, “size_id”:33, “region_id”: 1, “backups_active”: false, “ip_address”: “127.0.0.1”, “private_ip_address”: null, “locked”: false, “status”: “active”, “created_at”: “2013-01-01T09:30:00Z” } ] } </pre> The “id” value is the droplet’s id. If you just want to get the id, you need to parse the returned json. Our community has written a number of API wrappers in different programing languages that could be helpful here. Search GitHub for “DigitalOcean” and you’ll see that there are hundreds of open source integrations using our API. Just about every language is covered.

If you just want to parse it on the command line, take a look at the “jq” tool. On Ubuntu, you can install it with: <pre> sudo apt-get install jq </pre> You can use it parse json directly on the command line. To get just a list of droplet ids, run: <pre> curl -X GET “https://api.digitalocean.com/v1/droplets/?client_id=$DO_CLIENT_ID&api_key=$DO_API_KEY” | jq “.droplets[] | .id” </pre>

In account panel, you can find your droplets list. Click in the link to open droplet page and then check it URL. It should be something like this: <a href=“#”>https://cloud.digitalocean.com/droplets/XXXXX</a>

Where XXXXX is your droplet ID.