How to run a Heroku rake task via the API

For various reasons I was looking for a way to make a Heroku app run a rake task on another Heroku app. I looked into using the excellent Heroku API to achieve this, but couldn’t find any documentation on the subject. After a little bit of playing around, I discovered that you can achieve it by making a POST HTTP request like so:

curl -n -X POST https://api.heroku.com/apps/<your-heroku-app>/ps \
-H "Accept: application/json" \
-H "Authorization: $TUTORIAL_KEY" \
-d "command=rake my_rake_task"

(see here for details on how to build the $TUTORIAL_KEY variable)