I tried to make an API using apps-script doGet() function. I am able access the content of this API on my browser using appropriate authentication steps but am unable to access the same using another apps-script project.
The API looks as follows and is published as web app.
function doGet(request){
var parameters = request.parameters;
var request_id = parameters.id;
var response_obj = getObjectById(request_id);
return ContentService.createTextOutput(JSON.stringify(response_obj)).setMimeType(ContentService.MimeType.JSON);
}
and request is simply made using
const content = UrlFetchApp(url).getContentText();
is there a fundamental mistake or is there an authentication procedure that can be carried out so as to access this content
Answer found thanks for the help guys
what i needed was an authentication procedure and apps-script is very generous with that
refer Using AuthToken obtained via ScriptApp.getAuthToken() to call web apps in GAS
I was able to implement the solution using the following snippet for authentication
var token = ScriptApp.getOAuthToken();
var header = {"Authorization":"Bearer " + token};
var options = {
"method":"GET",
"headers": header,
"muteHttpExceptions": true
};
const content =UrlFetchApp.fetch(url, options).getContentText();