CORS error when trying to access web url generated using "projects.deployments.create".

105 views
Skip to first unread message

George Blackwood

unread,
Sep 24, 2023, 12:23:25 PM9/24/23
to Google Apps Script Community
Hello, in my Google Sheet, i have setup an automatic deployment script, that basically deploys the GAS when clicked on a button in my Sheet document: 
function deployWebApp() {
let scriptId = ScriptApp.getScriptId();
let url = `https://script.googleapis.com/v1/projects/${scriptId}/deployments`;
var params = {
"method": 'GET',
'muteHttpExceptions': true,
headers: {
Authorization: `Bearer ${ScriptApp.getOAuthToken()}`,
},
"versionNumber": 123,
redirect: "follow",

}
var response = UrlFetchApp.fetch(url, params);
var deploymentURL = null;
if ( response && JSON.parse(response.toString()).deployments) {
var deploymentURL = `https://05cad5eeae.nxcli.io/proposal/walmart45?id=${JSON.parse(response.toString()).deployments[0].deploymentId}`;
SpreadsheetApp.getUi().alert('Web App deployed Successfully - Check the URL and newly generated password for accessing the app' );
}  


My goal is to get the Sheet's data from remote website. 

deploymentId generated by deployWebApp function is this "AKfycbxnSlOb2p_Q676aG7SSaRnriBGRjVzdzi8oZQrrBAdG"
Web App Url generated by this deployment causes CORS error when requested to get the data. 

But if I deploy the GAS manually, the deploymentID is much longer: AKfycbxn5zZ8SsAQmQSTPsEskpPDAy5EsDZp5vEsur6gACRL8gWaUd7BtrT4jA4d_WbWOd-r4A
Web App Url generated by manual deployment works.


Please let me know if you need more context to understand what could be issue.
I've spent many hours trying to figure out what is the problem......


Reply all
Reply to author
Forward
0 new messages