How to get `type` for credentials API?

Hi there!

I’ve just started to play around with the n8n API itself and after investigating the /credentials endpoint (see API reference - n8n Documentation), I wonder where to find all the different type values. Is there a list available, where I can see the mapping for each node with the corresponding type value?

For example what is the type for Google Sheets? Or Google Drive? And how to find out by myself?

Best,
Sven

I am looking for the same thing. There is not enough example to create a credential through API.

I checked here; API reference - n8n Documentation

In docs, it is giving something like this below BUT doesn’t say anything about TYPE or DATA structure,

AND this example doesn’t work.

{
  "name": "Joe's Github Credentials",
  "type": "github",
  "data": {
    "token": "ada612vad6fa5df4adf5a5dsf4389adsf76da7s"
  }
}

Hey @svzi and @onurbolaca,

It is not ideal but you can find the types in the credential files, The property to use would be the name so for Google Sheets it would be googleSheetsOAuth2Api and Google Drive is googleDriveOAuth2Api, Just for Discourse which we are using now uses discourseApi

OAuth credentials are typically a bit trickier to manage with the API as it won’t do the verification process it would only allow you to add a new credential which a user would still need to interact with.

That GitHub one the type should be githubApi and it bugs me that the example is wrong, I am going to get a ticket created for that now.

Hey Jon, thanks for your quick reply!

And how about the data structure?

What should be the data going into “data” part?

{
  "name": "Joe's Github Credentials",
  "type": "github",
  "data": {
    "token": "ada612vad6fa5df4adf5a5dsf4389adsf76da7s"
  }
}

You can find that in the credential file as well or by using the schema search, In this case for GitHub it would be…

{
  "name": "Joe's Github Credentials",
  "type": "githubApi",
  "data": {
    "user": "joe",
    "accessToken": "ada612vad6fa5df4adf5a5dsf4389adsf76da7s"
  }
}

I see Jon, thank you for your directions!

So for anyone who is looking for this in forums,
So what I did was download my worklow (it downloads as json) and analyze the json for spesific types or id’s.

I used something like this and it worked;

{
  "name": "Joe's Github Credentials",
  "type": "httpHeaderAuth",
  "data": {
   "name": "127.0.0.1",
   "value": ""   
  }
}

So, above httpHeaderAuth is the credentials part of Http Request node,

And for credentials for IMAP Mail Node, I tried this one on postman and it didn’t worked but it gave me an error message that includes all the fields below.

{
  "name": "Joe's Github Credentials",
  "type": "imap",
  "data": {
   "name": "127.0.0.1",
   "value": ""   
  }
}

In this error message, it tells me about all the fields I should add into body.

{
    "message": "request.body.data is not allowed to have the additional property \"name\",request.body.data is not allowed to have the additional property \"value\",request.body.data requires property \"user\",request.body.data requires property \"password\",request.body.data requires property \"host\",request.body.data requires property \"port\",request.body.data requires property \"secure\",request.body.data requires property \"allowUnauthorizedCerts\""
}

Thank you guys!

Now I’m gonna write this error only to help people because I have been searching community forum for this;

It is giving me this error which I couldn’t understand even though I tried different combinations of data types the body;

request.body.data is not of a type(s) number,request.body.data is not of a type(s) boolean,request.body.data is not of a type(s) boolean

my data;


{
  "name": "Joe's Github Credentials",
  "type": "imap",
  "data": {
   "user": "[email protected]",
   "password": "12345678rterg",
   "host": "imap.gmail.com",
   "port": "993",
   "secure": "true",
   "allowUnauthorizedCerts": "false"
  }
}

I also tried to make the fields of boolean with 1 and 0.

But I found a solution for that, it is about sending data types in the right way;

YOURHOST/api/v1/credentials/schema/imap

On the last part of url (imap), use the type of your node that you use credentials in. To find the type, download your workflow and examine it as it is json and find the names from credentials parts of the json.

After you put the right type on this get request;

image

And fill the body;

{
  "additionalProperties": false,
  "type": "object",
  "properties": {
    "apiKey": {
      "type": "YOURAPIKEY"
    },
    "domain": {
      "type": "YOURHOSTADDRESS"
    }
  },
  "required": [
    "apiKey",
    "domain"
  ]
}

You will have all the structure of the data;

{
    "additionalProperties": false,
    "type": "object",
    "properties": {
        "user": {
            "type": "string"
        },
        "password": {
            "type": "string"
        },
        "host": {
            "type": "string"
        },
        "port": {
            "type": "number"
        },
        "secure": {
            "type": "boolean"
        },
        "allowUnauthorizedCerts": {
            "type": "boolean"
        }
    },
    "required": [
        "user",
        "password",
        "host",
        "port",
        "secure",
        "allowUnauthorizedCerts"
    ]
}

And don’t use any → “”

For boolean and number values;

{
  "name": "Joe's Github Credentials",
  "type": "imap",
  "data": {
   "user": "[email protected]",
   "password": "12345678rterg",
   "host": "imap.gmail.com",
   "port": 993,
   "secure": true,
   "allowUnauthorizedCerts": false
  }
}
3 Likes

And I have one question,

 "nodesAccess": [
        {
            "nodeType": "n8n-nodes-base.n8n-emailReadImap"
        }

Should I use this part in the body when creating credential with API? If so, what does it do?

Under the Details for the credentials there is a little bit where you check what nodes can use a credential, I don’t think that feature is currently working and is probably not needed anymore but for now I suspect you can skip it.

2 Likes

Thanks a lot for figuring that out @onurbolaca !

@Jon I suggest that the docs should get updated for this important use case. The doc is stating this url: /api/credentials/schema/{id} which is a) wrong (because of missing /v<version-number> after the /api part) and b) confusing about the id. What @onurbolaca used in his screenshot is way more self-explanatory: credentialTypeName. Ideally the user should be provided with a few samples and how to find out about the available credential types.

1 Like

I’ve just prepared a PR for this:

2 Likes

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