So my app creates spreadsheets programmatically as our projects expand (a new spreadsheet for each project). Each spreadsheet has a container-bound script that has some javascript in it to give the spreadsheet some extra functionality. Now I need all the scripts attached to these spreadsheets to use the same GCP project. I know how to set the GCP project manually (from this article), but I need to be able to set the GCP project programmatically when the spreadsheets are created.
I figure this can be done using UrlFetchApp, but I can't figure out the url that the "Set Project" button uses to make this happen. I tried inspecting the html on that settings page, but it's like 16000 lines of code, and while I found the button, I can't figure out the url it posts to.
Can someone help me out here? I need either the formatting of the url post, or another method to set the GCP project of a script with Apps Script.
Here's my code that I'm planning to use:
function changeGCPproject() {
const scriptId = '1Q8Frqjb6vh5....';
const gcpProjectNumber = '596....';
const url = `https://script.google.com/home/projects/${scriptId}/whateverformat?projectNumber=${gcpProjectNumber}`; //this is the url formatting that I need
const token = ScriptApp.getOAuthToken();
const params = {
method: 'post',
headers: {
Authorization: 'Bearer ' + token,
},
muteHttpExceptions: true
};
UrlFetchApp.fetch(url, params);
}
Thanks!