Reputation: 798
I am trying to read deployment information (version number and description) of google sheets addon during runtime using java script.
I found this web app related post. I am not sure whether it is different as my GAS is not web app. However I also tried this API here and it looks OK, I got all the script deployments info when supplying only the script ID.
I modified appsscript.json
to include all script required scopes (until so now it looks like that
{
"timeZone": "Asia/Jerusalem",
"dependencies": {},
"exceptionLogging": "STACKDRIVER",
"runtimeVersion": "V8",
"oauthScopes": [
"https://www.googleapis.com/auth/script.deployments",
"https://www.googleapis.com/auth/script.deployments.readonly",
"https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/userinfo.profile",
"https://www.googleapis.com/auth/script.container.ui",
"https://www.googleapis.com/auth/spreadsheets"
]
}
this is the call to the API
function getDeployments(){
let OAuthToken = ScriptApp.getOAuthToken();
let id = ScriptApp.getScriptId();
var url = 'https://script.googleapis.com/v1/projects/'+ id + '/deployments';
var options = { "muteHttpExceptions": true,
"headers": {
'Authorization': 'Bearer ' + OAuthToken
}
}
var response = UrlFetchApp.fetch (url, options);
console.log( "util.getDeployment" ,response.getResponseCode())
}
but this call returns http code 403. Please advice
Upvotes: 2
Views: 616
Reputation: 798
@Tanaike guiding question helped a lot.
Checking the response.getContentText()
as opposed response.getContent()
I checked before made the issue clear. The latter returned array of numbers, whereas the response.getContentText()
returns readable string.
Problem was the App script API was has not been enabled. Enabling this API solved the problem.
Upvotes: 1