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.
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!
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>
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.
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.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.