Luckily it wasn’t as complicated as it originally appeared — in a good part, because OAuth wasn’t necessary, just an API KEY from Heroku on their Manage Account page.
HEROKU_ADDRESS = 'https://api.heroku.com/apps';
function getApps() {
// Get all apps of Bearer, including their IDs and names. Either ID or name can be used later on as APP_ID.
var options = {
'method' : 'get',
'headers' : {
'Accept': 'application/vnd.heroku+json; version=3',
'Authorization': 'Bearer '+ HEROKU_API_KEY
},
};
var response = UrlFetchApp.fetch(HEROKU_ADDRESS, options);
Logger.log(response.getContentText());
}
function getConfigVars() {
// Get all config-vars of App
var options = {
'method' : 'get',
'headers' : {
'Accept': 'application/vnd.heroku+json; version=3',
'Authorization': 'Bearer '+ HEROKU_API_KEY
},
};
var response = UrlFetchApp.fetch(HEROKU_ADDRESS+"https://stackoverflow.com/" + APP_ID +'/config-vars', options);
Logger.log(response.getContentText());
}
function updateConfigVars(newConfigVars) {
// Set/Update some config-vars of App
// returns all config-vars
var options = {
'method' : 'patch',
'headers' : {
'Accept': 'application/vnd.heroku+json; version=3',
'Authorization': 'Bearer '+ HEROKU_API_KEY,
'Content-Type': 'application/json'
},
'payload': JSON.stringify(newConfigVars)
};
var response = UrlFetchApp.fetch(HEROKU_ADDRESS+"https://stackoverflow.com/" + APP_ID +'/config-vars', options);
Logger.log(response.getContentText());
}
function delConfigVar(ConfigVarName) {
// Delete a config-var of App (set to null)
// returns all remaining config-vars
var ConfigVar2del = {};
ConfigVar2del[ConfigVarName] = null;
var options = {
'method' : 'patch',
'headers' : {
'Accept': 'application/vnd.heroku+json; version=3',
'Authorization': 'Bearer '+ HEROKU_API_KEY,
'Content-Type': 'application/json'
},
'payload': JSON.stringify(ConfigVar2del)
};
var response = UrlFetchApp.fetch(HEROKU_ADDRESS+"https://stackoverflow.com/" + APP_ID +'/config-vars', options);
Logger.log(response.getContentText());
}
function del() {
delConfigVar('name');
}
function update() {
var newConfigVars = {
'name': 'some value',
'test': 770
};
updateConfigVars(newConfigVars);
}
With these functions one can get info on all of Bearer’s Heroku apps, including their names and IDs that can be subsequently used to get all config vars of the app, or modify/delete some of those config vars.
solved Is there a sample GAS code for interacting with Heroku API?