Heroku run via their node-heroku-client

39 views Asked by At

How can i use the heroku run command via the node-heroku-client?

I want to drop and create the tables in a database via herokus node-heroku-client, but I don't find the endpoint for that. Is there an endpoint in their rest-api that works like this.
I could do this in the webinterface, but I want to do it programmatically.

Isn't the node-heroku-client suppose to be a wrapper for this?

This is pseudo code of what I need, because the the second endpoint doesn't exist:

const Heroku = require('heroku-client');
const heroku = new Heroku({ token: 'xxx' });

const app_name = 'app_name';

heroku.get(`/apps/${app_name}/dynos`, { headers: { 'Accept': 'application/vnd.heroku+json; version=3' } })
    .then(response => {
        console.log(response)

        // TODO: loop through all dynos and run the command
        const app_id = response[0].app.id;
        const dyno_id = response[0].id;
        const command = 'echo hello world';

        return heroku.post(`/apps/${app_id}/dynos/${dyno_id}/console/run`, {
            headers: { 'Accept': 'application/vnd.heroku+json; version=3' },
            body: {
                command: command
            }
        });
    })
    .then(response => {
        console.log(response);
    })
    .catch(error => {
        console.error(error);
    });
0

There are 0 answers