Question

Working with long DIgitalOcean API commands

I have this very long and heavy DigitalOcean API command to rebuild droplet (I have a mistake there which I’m trying to figure out but it’s just for example to longevity problem).

I think it would be better of to work with multi-lined, because in one long row it’s just extremely uncomfortable to maintain. For example, look how long this one liner is:

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer 81206074d17245ba5d106d788b9edfea9947b1712ab47efgd6888e67f2e79957" -d '{"type":"rebuild","image":"ubuntu-16-04-x64"}' "https://api.digitalocean.com/v2/droplets/3164450/actions" 

Maybe it’s best to do:

curl -X POST \
-H "Content-Type: application/json" \
-H "Authorization: Bearer 81206074d17245ba5d106d788b9edfea9947b1712ab47efgd6888e67f2e79957" \
 -d '{"type":"rebuild","image":"ubuntu-16-04-x64"}' \
"https://api.digitalocean.com/v2/droplets/3164450/actions" 

Maybe something extra (a bash function? a Bash script?)

Please share any tip, thanks!


P.S. I’ve already deleted that token, I just gave it for the example here.

Show comments

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.

Andrew SB
DigitalOcean Employee
DigitalOcean Employee badge
February 1, 2018
Accepted Answer

Breaking it up into multiple lines definitely makes it more readable and easier to understand. You might also be interested in looking at the doctl command line tool. The same command using it would be:

doctl compute droplet-action rebuild 3164450 --image ubuntu-16-04-x64

If you’re are using it in a script, you can also pass --output json in order to have the same JSON response you would receive using cURL.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel