Select credentials via expression

Hi,

When creating an HTTP Request node, I would like to be able to dynamically select the credentials set to use based on an expression. It is not exactly as Access saved credentials from "expressions" as I don’t really need to access the credentials itself but only to tell HTTP Request node which credentials to use.

My use case:

  • I have 3 environments (dev, test, prod)
  • When an event is detected on any of these envs, it triggers a n8n webhook. The payload contains the environment.
  • A unique workflow for the 3 envs given the only diff is the base url (api.-mytool.tld) and the credentials.

“Simply” adding the expression support to the credentials selector would do the trick as I can store 3 different credentials following naming convention (-mytool).

Thanks

Seconded on this, and I have a use case - in my post Expression in credentials - only uses first item - Questions - n8n I was trying to attack my problem a different way (using an expression inside a credential) which didn’t work. If instead I could select the right credential using an expression, I would be able to have one workflow that does the same thing using multiple different credentials, instead of having to maintain a workflow for each credential.

This feature would greatly simplify having to duplicate workflows all because the referenced credential changed.

For example, if you’re building any sort of workflow using OpenAI and want to juggle more than 1 credential within a single workflow – that’s currently not possible:

image

4 Likes

Was about to create a feature request for this but I found this one! +1 from me. Use case is similar to the above. Multiple users on a platform where oauth is in play and service accounts are not available. I’d have to create a workflow for every user and then update every workflow every time I needed to make a change.

1 Like

This is a must-have. Today I’m obligated to replicate many workflows just to change the Credential tickbox :frowning:
If I need to change something related to this workflow I’ll need to change on every replica :man_facepalming:

16 Likes

I have similar use case to use different db credentials base on the environment. It would be nice to have functionality to select a credental based on some variable.
However, my current workaround is to create a separate Workflow with Webhook for each environment. There I set what environment this run is for. I could handle it with one Webhook and take env as a parameter, but this way I can set the webhook security separately for each environment and if anyone gained access to one of the webhooks, no unauthorized person would interfere with other environments.
Then I do Execute worklfow with the main logic.

In the main workflow, in the place where I have to query the database, I combine information about the environment with the query to the database and send it to a separate workflow that selects the appropriate connection. This way I don’t have my main workflow cluttered with many unnecessary nodes.

In the connection selection workflow, I have nodes for each environment and I choose the appropriate one depending on the environment parameter.
This is better than using expression in Credential settings itself to fill in the data, because you then have to provide the connection data directly in the workflow. This way we do not provide plaintext credential.

Not entirely sure this is exactly the same thing I’m looking for, but it’s similar enough that I think it goes under the same banner, and could be solved by the same feature.

In a workflow where there are numerous calls to a service that ALL use the same credential item, it would be very useful to be able to set a credential name in one place (e.g. Edit Fields (Set) node) and have all the “credential bearing” nodes pick up their credential settings from an expression referring to that “workflow-global” value. Currently I have found no way to modify the credential references in multiple nodes within a single workflow without opening each node separately and changing the credential selections manually one by one.

Wondering if it might be possible, as an alternative to re-working every credential-bearing node type to support expressions, to implement a new “Credential-Set” node, that could be added early in a workflow, which would provide workflow-local aliases for a handful of system credential items. If that were to inject “local” credential items (proxies) into scope for the remainder of the workflow execution, maybe the nodes using the credentials, especially specific-node-type credentials items like “Spotify OAuth2 API” wouldn’t even know the difference. Also, the “Credential-Set” node could support expressions to select a system credential item on behalf of all the other node types.

Here for the same feature. I wonder if it would be a security risk if they create a node that does this.

You can use this for now.

1 Like

thank you @BramKn This is a game-changer. My workaround was to access the docker database with the Postgres node but this is much more straightforward. :pray:

1 Like