Question

Shell script for automatic snapshot - API

  • Posted August 11, 2014

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.

Subscribe
Share

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

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.

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'