Set Cookie in Follow Redirects from the first response

We have an API that will return cookie and redirect to next URL, before redirection we need to set cookie to redirection URL, On N8n cookie is handled manually, so redirection failed on authentication because of cookie

On my API, have this behavior every API call return different cookie, if input cookie not provided or not valid

  • n8n version: 1.63.4
  • Database (default: SQLite): Postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker
  • Operating system: Linux

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Hi @Sri_Balaji_Velan_OPS

Thanks for posting here and welcome to the community! :cupcake:

I am not sure I understand exactly what your use case is but from the top of my head it sounds like you could probably use the staticData function to help.

Can you share the workflow that you have so far and ideally with some pinned dummy data to demonstrate what you’re getting back from your API and what you need to send?

Thanks! :pray:

Tip for sharing your workflow in the forum

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

Make sure that you’ve removed any sensitive information from your workflow and include dummy data or pinned data as much as you can!


For example, If I’m calling login API, it will return cookie and auto-redirect to another API, but on redirection it must pass the new cookie, On n8n, we don’t have auto cookie save and auto pass cookie option available

Ah thank you, I understood now!

So actually, you should be able to do this within the HTTP node. I don’t know the data structure of your API but if the cookie is being sent in the body you could capture it from within the $response.body and then include it in the redirect (in body or header) - depending on how you need to pass the cookie)

Here’s the config:

I hope this makes sense? :slight_smile:

Thanks, but this option also not working, may be HTTP node support cookie my default option, it may better

For now, I found another solution, like to not allow redirect and allow error response, so I am able to get the actual auth cookie and do the other calls separately

image

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.