Created
September 13, 2019 23:09
-
-
Save mbaynton/7118f8108601b09a05a15a9316fbaeff to your computer and use it in GitHub Desktop.
JS ad-hoc Pantheon workflow invocation and status check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// not sure if it's the json.trace_id or json.id that is correct for the second, status check call | |
dumper = function(response) { console.log(response.status); response.text().then( text => console.log(text) ) } | |
function checkWorkflow(site_id, env_id, workflow_id) { | |
p = fetch("/api/sites/" + site_id + "/environments/" + env_id + "/workflows/" + workflow_id, { | |
credentials: "include", | |
headers: { | |
"accept":"*/*", | |
"accept-language":"en-US,en;q=0.9,de;q=0.8,fr;q=0.7,ro;q=0.6", | |
"content-type":"application/json; charset=UTF-8", | |
"sec-fetch-mode":"cors", | |
"sec-fetch-site":"same-origin", | |
"x-requested-with":"XMLHttpRequest" | |
}, | |
method: "GET", | |
mode: "cors" | |
}); | |
p.then(dumper, dumper); | |
}; | |
fetch("/api/sites/0ba30b11-ee59-49a2-89c0-e7b865f00c6f/environments/dev/workflows", { | |
credentials: "include", | |
headers: { | |
"accept":"*/*", | |
"accept-language":"en-US,en;q=0.9,de;q=0.8,fr;q=0.7,ro;q=0.6", | |
"content-type":"application/json; charset=UTF-8", | |
"sec-fetch-mode":"cors", | |
"sec-fetch-site":"same-origin", | |
"x-requested-with":"XMLHttpRequest" | |
}, | |
body: JSON.stringify({ | |
params: { | |
primary_domain: "ztest.mbaynton.com" | |
}, | |
environment: "dev", | |
type: "set_primary_domain" | |
}), | |
method: "POST", | |
mode: "cors" | |
}).then(function(response) { console.log('workflow initiated.'); response.json().then( json => checkWorkflow(json.site_id, json.environment_id, json.trace_id) ) }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment