Question

Shell script for automatic snapshot - API

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.


Submit an answer

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!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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'