We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
Jun 24, 2021 3:03 PM
Hi there, I'm using HubSpot Serverless functions and I have a simple use-case where I try to pass along all cookies I recieve from my API to my Client.
So basically I use the standard approach (like described in the docs) and it looks something like this:
exports.main = (context, sendResponse) => {
axios.post("https://myapi.com", someDataToPass).then(function response(res) {
sendResponse({
body: response.data,
statusCode: 200,
headers: {
"Set-Cookie": response.headers['set-cookie']
}
});
});
};
Everything works well, except my cookies aren't passed along to the client. I've also tried to replace "Set-Cookie" with other params like "Cookie" or "Cookies" in case any of that work but no success.
Surprisingly, if I change "Set-Cookie" to "Location" the data is submitted to the client like it should. "Location" is also the only parameter that is documented here: https://developers.hubspot.com/docs/cms/features/serverless-functions/reference#redirect-by-sending-.... There is no further reference for other "headers" parameters like "Set-Cookie" for instance so I assume they just don't work with hubspot?
Does anyone have more insights about this?
Jul 1, 2021 3:29 AM - edited Jul 1, 2021 3:31 AM
Hi @joviedo- wow it seems to work now!
Only one more question. I'm actually trying to send multiple cookies - not just one. According to http specs (https://developer.mozilla.org/de/docs/Web/HTTP/Headers/Set-Cookie) "multiple Set-Cookie headers should be sent in the same response". But if I try to do that, only one of the Set-Cookie Headers arrives:
Jun 30, 2021 3:10 PM - edited Jun 30, 2021 3:11 PM
Hi @TGerhard Set-Cookie was not supported as a response header but it was added recently. Could you try again with Set-Cookie?
Jun 25, 2021 1:02 PM
Hey @TGerhard
I believe location is strickly for a permenant redirects. Have you tried using the cookie header?
Jun 25, 2021 1:09 PM
Hi @Kevin-C
yes, I have tried "Cookie" instead of "Location" and also "Set-Cookie" like in my example above but when I checked the response (in chrome dev tools) it seems like the cookie / Set-cookie Header was removed or rather never sent to the client at all. When I tried with "Location" the header was submitted and i was able to se it in the developer tools.