How to use basic auth with dynamic username/ password

Hello everyone,

I hope you’re all doing well! I have a question about using basic authentication with dynamic usernames and passwords. How can I implement this in an HTTP request within my flow?

Information on your n8n setup

  • Running n8n via cloud
  • win10:

Hi @brian_silva, welcome to the community :tada:

You can use n8n expressions in your credentials:

So to use dynamic usernames and passwords you’d simply want to create a Set of Basic Auth credentials and then have expressions referencing your incoming username and password fields.

If you only process one item per execution that’s all there is to it.

If you have more than one item, it’s slightly more complex. This is because n8n will only evaluate these credential expressions once per run, even when a node processes multiple items (whereas outside of credentials expressions will be evaluated for every single item). So if your HTTP Request node processes multiple items in each run and you want to use different credentials for each you’d need to use the Loop Over Items node and split your items in batches of 1 (in older versions of n8n this node is called “Split in Batches”) so n8n starts a new node execution for every single item.

Here’s a quick example for this:

Hope this helps :slight_smile:

1 Like

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