Droplet ID Number to Place in Variable

Posted June 14, 2014 9.6k views
I can find a droplet id number and other information by ... curl -X GET "" But, I want to retrieve just the id number, so it can be added to a variable. Any help appreciated. Thanks.

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.

Submit an Answer
3 answers
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: Where XXXXX is your droplet ID.
If you want to find the droplet ID programmatically, you can get a list of all active droplets with:
curl -X GET "$DO_CLIENT_ID&api_key=$DO_API_KEY"
The results will look like:
  "status": "OK",
  "droplets": [
      "id": 100823,
      "name": "test222",
      "image_id": 420,
      "region_id": 1,
      "backups_active": false,
      "ip_address": "",
      "private_ip_address": null,
      "locked": false,
      "status": "active",
      "created_at": "2013-01-01T09:30:00Z"
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:
sudo apt-get install jq
You can use it parse json directly on the command line. To get just a list of droplet ids, run:
curl -X GET "$DO_CLIENT_ID&api_key=$DO_API_KEY" | jq ".droplets[] | .id"

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.