Custome Credentials json example

Hey i have a question.

If we have api which is not exists in n8n but we want to add it to credentials we can use Custom Auth yes?

But i can’t find any information how json code should look like to this work good for example headers etc.

Then if we set up this header there it’s automatically added to node eg http ?

Thanks for any help.

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:

Hey @daknow,

The custom auth option is more for if you need to set multiple header or body values that you can’t do in the normal credentials, As an example if you wanted to add 2 header keys you could use…

{"headers": {"X-AUTH-USERNAME":"username", "X-AUTH-PASSWORD": "password"}}

If it was a form based login you can do something like

{"headers": {"Content-Type":"application/x-www-form-urlencoded"}, "body" : {"user": "username", "pass":"password"}}

and the last example I have on my test instance is for query string which would be

{"qs": { "method": "password", "credentials": { "username": "exampleUser", "password": "abc123" }}}

Hopefully this helps.

Hey Jon,
Thanks for the great examples, I know it wasn’t the same thing, but I tried to use custom auth for my scenario but couldn’t. My scenario is that I have to authenticate at the body with a user/password in order to get a Bearer Token that expires after 5mins. My main concern is that I don’t want to store the password in plain text.
Are there any options for us n8n self-hosted? or must we upgrade to paid plans that offer ‘Global Variables’ (Pro Plan) or ‘External Secret Integration’ (Enterprise Plan).
Thanks in advance.

You can use the crypto node to encrypt the key, use convert to file node, then use read/write files from disk node. Then you can read the file anywhere by using the same method in reverse and overwrite the path whenever.

1 Like

thanks for the info, I will take a look, thanks,

Hey @arlopeznieto,

What you could do is put the username and password as a stored credential which will be encrypted in the database, Use the HTTP Request node with that credential to get your token then in following http request nodes use the token outputted from that node.

This will save the Bearer token in the logs if you have execution logging enabled so I would disable it for that workflow that way the token won’t be in the logs. Using variables or external secrets won’t really help with this one, Although if you are self hosting you could make a custom credential with some javascript that gets the bearer token and uses that as needed.

Thanks for the reply, I’ve been trying the different auth options but I haven’t been able to make any of these work at the body level. And since at the body level I need to send both username and password, most of the credentials only have 1 key-value pair, so I’m still a little lost on how to use the built-in auth at the body level, and I couldn’t make the Custom json auth work either. (Basic Auth, Custom Auth, Digest Auth, Header Auth, OAuth1 API, OAuth2 API, Query Auth)

Hey @arlopeznieto,

You would need to use the custom auth option to send the credentials in the body a bit like the form based example above then use the output from that request to use the token. But depending on the service you are using it may be easier to make your own credential as a custom node in n8n then you would only need the one credential and it can take care of getting and storing the token.

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