Shell script for automatic snapshot - API

August 11, 2014 1.3k views


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.

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": "",
  "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 "" -H "Authorization: Bearer $TOKEN" \
| jq '.droplets[] | select(.name=="") | .id'
by Mitchell Anicas
In this tutorial, we will teach you how to get started with the DigitalOcean API v2.0. We will show you how to generate personal access tokens, which will be used for authentication, and show a few examples of how the API can be used. The DigitalOcean API allows you to manage Droplets and resources within the DigitalOcean cloud in a simple, programmatic way using conventional HTTP requests.
Have another answer? Share your knowledge.