How can we add credentials through an API?

I am able to find the API for creating a workflow. What i cant find is how to set the credentials for the individual nodes. For instance, a HTTP request node has an Header Auth credentials which has an api key which is passed as a header in the request. How do we set these through an API?

Hey @premkagrani,

I am not entirely sure what the question is but I will take a bash at it anyway. Assuming you want to know how to add credentials using an API approach it looks like you would need to use the patch method on /rest/workflows/{workflow_id} and send the full json for your workflow making sure you include the below to your HTTP Request nodes parameters…

"authentication": "headerAuth",

and the object below in the same object as your HTTP Request.

"credentials": {
    "httpHeaderAuth": {
    "id": "Credential ID",
    "name": "Credentials Name"
  }
}

Hi @Jon , thanks for the reply. The object above contains the credentials name. Although I found another API which has the details of all the credentials info that we supply. That name is mapped here in the /rest/workflow API body. The below is the API I noticed would add a new credential →

POST /rest/credentials

{
    "name": "Local Rabbit",
    "type": "rabbitmq",
    "data": {
        "hostname": "127.0.0.1",
        "username": "guest",
        "password": "guest"
    },
    "nodesAccess": [
        {
            "nodeType": "n8n-nodes-base.rabbitmq"
        },
        {
            "nodeType": "n8n-nodes-base.rabbitmqTrigger"
        }
    ]
}

Hi @premkagrani, thanks a lot for sharing! Keep in mind this is not an official API (yet) so use with caution as things might change with a future update.

It would also be great if you could vote on Official n8n API (and ideally also share your use case) for this feature to help planning our development efforts.

Thanks so much!

1 Like

Hi @MutedJam , thanks for letting me know. Is there a plan for an official API sooner in a few months. I am trying to work on a project where I would prefer to have the workflows created in my local environment through the N8N UI and later in production implement the same workflow through the helper APIs. I hope this helps.

This would be a question best answered by @sirdavidoff, so let’s see what he says on this :slight_smile:

We recognise that a product that is all about connecting APIs should have an official API :wink:

It’s definitely on the roadmap. But we’d like to make sure we get user management out the door first.

1 Like