How to Encrypt Credentials via API?


I’m trying to create basic credentials through the API. I made a POST request to /rest/credentials with the following parameters:

  • name
  • type
  • nodesAccess

The credentials are getting created but when I try to open the credentials from the editor UI I get this error :

There was a problem loading the credentials:
*Credentials could not be decrypted. The reason is that probably a different "encryptionKey" got used to encrypt the data than now to decrypt it.* 

I also tried adding encryptionKey as a body parameter but that didn’t work. Also is there a possibility we could add the User, Password of that credential through this API Call ?


Looking at the response it looks like the actual data is missing

Here an example that works fine for me:

  "nodes": [
      "parameters": {
        "requestMethod": "POST",
        "url": "http://localhost:5678/rest/credentials",
        "options": {},
        "bodyParametersUi": {
          "parameter": [
              "name": "name",
              "value": "Test Credentials"
              "name": "type",
              "value": "httpBasicAuth"
              "name": "nodesAccess",
              "value": "={{JSON.parse('[{\"nodeType\": \"n8n-nodes-base.httpRequest\"}]')}}"
              "name": "data",
              "value": "={{JSON.parse('{\"user\": \"user1\", \"password\": \"password1\"}')}}"
      "name": "HTTP Request Create",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
  "connections": {}
1 Like

Cool, Now its working
Thanks @jan :grinning:

Great to hear! Have fun!