HTTP Request Node - Body Auth - How to save Credentials and Token

Dear n8n Community,

I have a endpoint which needs to authenticate at the body level and then generates a access token.

My problem is that I want to create and save a credential set to save that nodes credentials encrypted inside n8n, which I did not manage.

Also that token generated should be saved inside the credentials till it expires and then auto-revoke a new token.

The node looks like this:

Maybe you have some ideas for that case?
I also tried and searched to create a expression to enter the credentials from a saved credential set, which was not possible.

Thank you

Hi @prononext, is the server you’re connecting to using OAuth2 by any chance?

If so, n8n can usually manage the token renewal for you. It also supports sending the credentials in the body if you select Body in the Authentication dropdown of your OAuth2 credentials:


Sadly it is not OAuth2, but maybe there is another way for this case?

I think in this case your best bet might be to save your secret in an external data store (such as a database) and read it in your workflows whenever needed.

You could also consider using an environment variable which you can read inside n8n through an expression such as {{ $env["MY_VARIABLE_NAME"] }}.

I have the exact same problem. And even though I think it should be easy to solve, there is something I am missing.

I am using n8n cloud solution.

I don`t know how to save environment variable - should i use ssh node? how do i authenticate?

I have also tried to save the credential to a file, but I got a permission denied when I`ve tried that. What path should i use that i have permission to save a file?

@MutedJam I`ve found no documentation about the n8n cloud installation. Could you point me to a solution please?

Hi @jgggr, welcome to the community!

You can’t access environment variables on n8n cloud I am afraid, so you would need to store the required values directly in your workflow.

Thank you for your fast reply.

I need to “save” the credential so i can use it until expires. If i just “set” the value it will be lost in the next run, right?

Let me be clear. I have to make an initial authentication sending my username and password in the body of an http request, just like the initial message in this thread. The server respond to me with a bearer token authentication. I will be using this token until expires, than i have to ask for another.

I have to save this token I’ve received to be used for many runs of the workflow.

This is my workflow.