Question

Shell script for automatic snapshot - API

Posted August 11, 2014 2.8k views

Hello,

I am trying to write a shell script to take snapshot of a droplet. Is there any option to get droplet name from droplet ID using curl?

Thanks in advance.

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.

1 answer

You should check out the full API documentation as well as this tutorial. They should point you in the right direction.

The /v2/droplets endpoint will return a list of of droplet objects with information about each one. The droplet’s id is included in this information. An abridged droplet object might look like:

{
  "id": 14,
  "name": "test.example.com",
  "memory": 512,
  "vcpus": 1,
  "disk": 20,
  "region": {
      ....

If you’re doing this with a shell script, I’d suggest looking into jq to parse the json objects. For instance, if you know the name of a droplet you can find its id with:

curl -X GET "https://api.digitalocean.com/v2/droplets" -H "Authorization: Bearer $TOKEN" \
| jq '.droplets[] | select(.name=="test.example.com") | .id'
Submit an Answer