Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add and remove Heroku Dynos through platform API

I want to add and remove Heroku Dynos through platform API Just like we do

ps:scale web=0

in Heroku toolbelt CLI.

I have already tried

POST /apps/{app_id_or_name}/dynos/{dyno_id_or_name}/actions/stop

but it doesn't do anything however the response has a status code of 200.

like image 219
ishaqbhojani Avatar asked Nov 24 '25 10:11

ishaqbhojani


1 Answers

As per the dyno stop ps:stop behavior outlined in this question:

Running ps:stop on dynos that are part of a scaled process will automatically be restarted. In Private Spaces, ps:stop will terminate and replace the dedicated instance running the dyno(s). To permanently stop dynos, scale down the process."

To scale down the dynos to 0 through the Platform API, you'll need to use formation API.

Formation List:

GET /apps/{app_id_or_name}/formation

$ curl -n https://api.heroku.com/apps/$APP_ID_OR_NAME/formation \
  -H "Accept: application/vnd.heroku+json; version=3"

Formation Update:

PATCH /apps/{app_id_or_name}/formation/{formation_id_or_type}

$ curl -n -X PATCH https://api.heroku.com/apps/$APP_ID_OR_NAME/formation/$FORMATION_ID_OR_TYPE \
  -d '{
  "quantity": 1,
  "size": "standard-1X"
}' \
  -H "Content-Type: application/json" \
  -H "Accept: application/vnd.heroku+json; version=3"

Sending quantity = 0 as a parameter will scale the dyno process to zero.

like image 133
ishaqbhojani Avatar answered Nov 27 '25 00:11

ishaqbhojani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!