Access cookie values

#1

I was wondering where and how to access cookie values from different end point paths when rendering an experience page?

I am setting a cookie from a workflow backing a /path1 endpoint and would like to be able to access it from another workflow backing /path2 endpoint.

Is that possible to access cookies values from a different path on the same domain?

0 Likes

#2

Hi Evan,

Of course, you can, here is some documentation on how to set a cookie using the Endpoint Reply Node. And here is some documentation on how to access a cookie from the payload.

Hope that helps,
Erin

0 Likes

#3

thanks @Erin_Thompson

I noticed that documentation, but I find in my testing the the cookie is not available when I access different paths.

I have various endpoints at /path1, /path2, /path3, which are severed by their own workflows with a Reply Node that renders a different dashboard page for each subfolder. If I set a cookie on /path1, it is not avaliable when I render /path2 or /path 3. I checked by browser information and I can see the cooking stored when accessing /path 1 but its not there when I access /path2 or /path3. It seems that the cooking function in the endpoint reply defaults to using the sub path and I couldn’t find an option to set the path to root to make it available on the entire domain. See attached screenshot.

0 Likes

#4

Well, I decided I set up an Experience App, and I created two paths /path1 and /path2, to see if I can reproduce the issue you are seeing. /path1 set the cookie cookie1 to chocolateChip using the Reply Node. So when I navigate to /path1 the cookie appeared.

And when I navigate to /path2 which does nothing with any cookies I can see this in the browser:

Can you give me more information on how you are setting the cookie since I can’t seem to reproduce your issue yet?

Thanks,
Erin

0 Likes

#5

Hi @Erin_Thompson

Thanks for that testing.

I can see the difference is that your cookie (which sounds very tempting by the way) shows a path of ‘/’ in your browswer. My browser shows ‘/demo/overview’ when I set the cookie using the workflow backing the ‘/demo/overview’ endpoint. I think having ‘/’ covers all your subfolders, but mine is constrained two levels deep.

I’m setting the cookie from a workflow with the screenshot below:

I have created exactly the same test that you have outlined using a new Application and just the bootstrap resources. And I got the same results: a cookie that persists no matter the path.

I’ve tracked down the difference but I can’t explain why. If you use path parameters at the end of the URL, you should be able to reproduce the issue. e.g. mypage/path1/{deviceId}

That causes a cookie on /path1 to be created with the constraint of /path1 applied to the cookie. If you remove the params, the cookie will have a path at one level closer to the root.

I did find a workaround by just using the Set-Cookie option in the Reply Header configuration. I set that to Set-Cookie mycookie=chocolateChip; Path=/. That worked!

It would be nice to have the option to specify the cookie path from within the configuration of the cookies in the Reply Node boxes.

Thanks!.

0 Likes

#6

Hi Evan,

So I can reproduce the behavior that you are seeing. I have filed a bug and hopefully, a fix will be out for the next release. I’ll post back when it has been released. Sorry for the inconvenience and glad you found a workaround.

Thanks,
Erin

0 Likes

#7

Thanks Erin,

Personally, I am not sure its a bug. I think in the absence of a path parameter, the browsers fill in the blanks. The fix might just be to have an input box for the path so the user can be specific about the scope of a cookie.

0 Likes