For people who like to make things

I recently needed to issue several dozen HTTP DELETE REST API calls of the form http://www.example.com/blah/n where n was a sequential version number. In this post I’ll show how to do this easily from the command line.


Update The nice folks at HockeyApp just pointed out that as far as HockeyApp is concerned, there is an API for deleting multiple versions. So while you don’t need to use seq for deleting versions from HockeyApp, it’s still a good tool to be aware of.


As I was showing someone how to deploy apps to beta testers, I tried to upload a tiny demo app to my account at HockeyApp. It failed because I was over my storage limit. I had to delete old versions of my apps from Hockey so that I could continue using it without upgrading to the next higher tier of service.

One of my apps had 60 versions that wanted to delete. I definitely didn’t want to delete them manually, so I turned to the API docs. Hockey’s help page conveniently shows the curl command to delete a version:

curl \
-X DELETE \
-H "X-HockeyAppToken: 4567abcd8901ef234567abcd8901ef23" \
https://rink.hockeyapp.net/api/2/apps/1234567890abcdef1234567890abcdef

This is where the command line comes to the rescue. I needed to wrap the curl command in a loop that goes from 1 to 60. To this I used the seq command that is available on Mac OS and Linux:

# Send a bunch of sequential HTTP DELETE requests
$ TOKEN=4567abcd8901ef234567abcd8901ef23
$ APPID=1234567890abcdef1234567890abcdef
$ for version in `seq 60 1`
do curl -w "$version: Result: %{http_code}\n" \
        -X DELETE \
        -H "X-HockeyAppToken: $TOKEN" \
        https://rink.hockeyapp.net/api/2/apps/$APPID/app_versions/$version
done

This will execute the curl command for version 60 down to version 1 using the appropriate token and app ids. I hope you find this as useful as I did.

© 2022 Aijaz Ansari
The Joy of Hack by Aijaz Ansari is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
Powered by Pelican