I want to pass a (HttpOnly) cookie to Google Apps Script doGet(e)
endpoint (e.g. from fetch(...)
on the client), but there doesn't seem to be any way to retrieve incoming cookies/headers out of e
.
I have tried logging all e
properties using
function doGet(e) {
return ContentService.createTextOutput(
JSON.stringify(e)
).setMimeType(ContentService.MimeType.JSON);
}
and querying it with curl
curl -L --cookie "name=Jane" "$webapp_endpoint"
curl -L --header "Cookie: name=Jane" "$webapp_endpoint"
Responses had no cookie info at all. Is it not possible to retrieve?
The e
parameter only provides query parameters (i.e., e.parameter
, e.parameters
) and does not expose HTTP headers, including cookies. This is a known and documented limitation of Google Apps Script Web Apps.
a possible workaround would be to send the cookie value explicitly as a query parameter
On the client side :
curl -L "https://script.google.com/macros/s/XXX/exec?token=Jane"
And in your doGet(e)
:
function doGet(e) {
const token = e.parameter.token;
return ContentService.createTextOutput(`Hello ${token}`);
}
hope this was of help to you