Running ‘heroku run:detached’ programmatically. How exactly?

heroku

Solution

You can use the platform API to to this, and create a dyno. See https://devcenter.heroku.com/articles/platform-api-reference#dyno-create

By sending a `POST` request to `/apps/your_app_name/dynos` with the following parameters:

- `command`, the command you wich to run.

- `attach`, set it to false.

This will create a one-off dyno and detach it. This is what the toolbelt does when you run the `run:detached` command. You can see how it works here: https://github.com/heroku/heroku/blob/01cd753570cb62b917843112fb29d1cdd43ba335/lib/heroku/command/run.rb#L65

Problem

I've tried googling and stackoverflowing this and all I get is links back to the API reference or examples of scaling dynos, which is not what I want. `heroku run:detached` is great as it just spins up a dyno with your app, runs whatever you want, then spins down the dyno. How do I achieve the exact same things but using the Heroku Platform API? I've seen people mention you have to use the `Dyno` endpoint on the API, but how? Can someone offer an exact example of how I would run the following from the API? ``` $ heroku run:detached --size 2x rake my_task.rb ```

Original source