Select HTTP credentials with an expression

Describe the issue/error/question

Hello the n8n community, I am currently trying to replicate the scenario 2 from this thread: Programatically passing credentials into a Workflow

So basically in my scenario a webhook will be received with the id of the credential to use in the next HTTP node. This id will be used in the credential expression of the HTTP node.
But I have no idea on what expression format is required for the HTTP node credential.

Please share the workflow

  "name": "My workflow 2",
  "nodes": [
    {
      "parameters": {},
      "id": "cb0c46fc-1d42-4c91-8147-2e71c0e2cabf",
      "name": "Start",
      "type": "n8n-nodes-base.start",
      "typeVersion": 1,
      "position": [
        240,
        300
      ]
    },
    {
      "parameters": {
        "path": "d347443f-d83f-44e0-ab7a-53da41bcfc5a",
        "options": {}
      },
      "id": "2e625920-5137-4325-b37a-ed7d3869e46f",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        560,
        300
      ],
      "webhookId": "d347443f-d83f-44e0-ab7a-53da41bcfc5a"
    },
    {
      "parameters": {
        "authentication": "genericCredentialType",
        "genericAuthType": "=id=3",
        "url": "https://test.com",
        "options": {}
      },
      "id": "278851ee-5f22-4a57-abb3-743c1d787e49",
      "name": "HTTP Request",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        780,
        300
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "Start": {
      "main": [
        []
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "HTTP Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {},
  "id": 2,
  "meta": {
    "instanceId": "f035f12a1ddb2fac6450268a9ac828a068fa985e94a2d18e402888547ec2f5e8"
  },
  "tags": []
}

Here is where I need to add the expression (the id number 3 is an example, the id will be received from the webhook)
image

Information on your n8n setup

  • n8n version: 0.193.5
  • Database you’re using (default: SQLite): no DB
  • Running n8n with the execution process [own(default), main]: ?
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: Docker

Hi @jsasportas, I don’t think it’s currently possible to use an expression in to select credentials by ID I am afraid.

You can, however, pass on individual values that will be used in your credentials. Say you want to use basic auth credentials and your webhook receives username and password in the query parameters of your webhook URL. You can then use an expression like {{ $json["query"]["username"] }} in your User field and {{ $json["query"]["password"] }} in your Password field:

Now whenever your HTTP Request node runs it would use the values coming in through from the Webhook node.

Or in other words, opening your webhook URL with ?username=foo&password=bar at the end will result in an HTTP Request using a username of foo and a password of bar.

Hi @MutedJam no problem, we will create a new workflow for each credential then, it will be easier to do since the credential type is Oauth2, so your solution is a bit harder to do.

Thank you,
Jordan

1 Like

Ah yes, that’s unfortunately true :frowning: There’s an open feature request to allow this for SMTP credentials over here: Send Email / SMTP Credentials: Choose by ID number (and expression)

You might want to leave a vote on it and perhaps add a comment that you’d like to see this feature in general, not just for the email node.

I voted thanks :slight_smile:

Just out of curiosity, what expression format is the field “Generic Credential Type” supposed to receive?
If I use an expression for this field, I cannot enter anything else for this credential.
image

Thanks,
Jordan