List stopped machines (or with a certain status generally) via API

Hello team,

I know that you can list machines via the CLI and can perform some shell based filtering to obtain those with a certain status (in my case stopped).

My question is whether there’s also API support for something like this planned? The docs don’t show this option.

For context: I’m using machines in a “serverless” way and end up with dangling stopped machines sometimes. I’d like to have a scheduled job clean them up via the API rather than having to manually type a CLI command.


The list machines endpoint returns all under your application.
You can filter by machines with the state of "stopped" :slight_smile:

I’ve done this recently using these calls (these are authenticates requests):

  • Call to GET<my-org>
    • Foreach app in the results, check app.machine_count, if greater than zero, then do further work.
      • Foreach app with a machine, run GET<app-name>/machines to get the machines and their state
curl -H "Authorization: Bearer `fly auth token`" \$MY_ORG

# Logic here to get JSON results and get each app with some machines

curl -H "Authorization: Bearer `fly auth token`" \$APP_NAME/machines

Thanks for the boilerplate, helps a lot!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.