How to authenticate to n8n with curl (login + reuse cookie/token)?

Hi @jabbson

I’m running a self-hosted n8n instance that already shows the login screen and requires my admin email/password. I would like to access workflow endpoints programmatically using curl.

My doubt is:

  • How do I first authenticate with my admin email/password using curl?

  • After logging in, how can I capture the session/cookie or token and reuse it for subsequent curl requests to protected endpoints?

A step-by-step example (login + follow-up request) would be really helpful.

Thanks in advance!

Hey @Nandhini_Subramaniya

when you start (trigger) your workflows you most certainly can do it with curl, For that you would need to create a webhook trigger in your workflow. Webhook allows to trigger your workflow with an http request. This way no need to deal with sessions, cookies or n8n authorization to begin with.

I understand that workflows can be triggered via webhooks, but my situation is a bit different.

When I start my n8n instance with the command:

n8n

the server starts successfully on port 5678, and when I open it in the browser I get the login page asking for my admin email and password. Example logs:

n8n ready on ::, port 5678
Editor is now accessible via: http://localhost:5678

What I would like to do is:

  • Instead of logging in through the browser UI,

  • Send my login credentials using curl and capture the session cookie or token,

  • Then use that cookie/token for subsequent curl requests to protected endpoints.

Can someone please explain how I can achieve this with curl.

Hey @Nandhini_Subramaniya 'hope all is good.
Is there a reason you would like to do it this way? I would really like to know the use case, which automating the automation system is useful and cannot be simplified to just using a trigger specifically created for this sort of thing.

The reason I’m asking about logging in with curl is because when I start my self-hosted n8n instance it always shows the login page asking for my admin email and password.

I want to test accessing the instance programmatically (without a browser) — basically to log in using curl, get the session cookie or token, and then make further requests.

I understand that webhooks and API keys are the recommended way to trigger workflows, but in my case I’d like to simulate the normal login process programmatically for testing and learning purposes.

There is n8n API can do these stuff. Why using the more hard-work way?

After you generate you api key.

You can get, create even execute the workflow using code only.


simulate the normal login process programmatically

That is a hard level of web crawling skill for non engineers.

If you want to learn that kind of skill. Maybe search python puppeteer.

It has the headless browser function that you can get the data from website without open any browser.

Thank you for your answer.

You are still not talking about the reason, you are talking about the way to overcome the login page. I am more interested in knowing why you need that, which problem are you trying to solve?

Hi, thanks for clarifying.

This is actually just part of my learning exercise. I’m experimenting with n8n to understand how authentication works under the hood.

For example, in a normal API I would first log in using curl with my email/password, receive a token or cookie, and then use that for subsequent requests. I’d like to practice the same flow with n8n, so I can better understand how its login/session mechanism works.

I know that in real use cases, webhooks or API keys are the right way to go — but here my goal is just to learn and replicate the login process programmatically using curl.

I see, thank you for explaining this, @Nandhini_Subramaniya.

If you want to learn, you better choose another website for learning as you won’t be able to easily achieve what you want with n8n and here is why. The UI in n8n is heavily based on javascript, which in order to execute you would require a javascript engine to run and curl doesn’t have a javascript engine. This limitation includes both the login page as well as the editor.

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