-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(n8nApi node): add core node for consuming the n8n API (#4076)
* feat(n8n node): create n8n core node for consuming the n8n API Co-authored-by: Michael Kret <michael.k@radency.com>
- Loading branch information
1 parent
67513e1
commit 929315f
Showing
10 changed files
with
1,206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
IAuthenticateGeneric, | ||
ICredentialTestRequest, | ||
ICredentialType, | ||
INodeProperties, | ||
} from 'n8n-workflow'; | ||
|
||
export class N8nApi implements ICredentialType { | ||
name = 'n8nApi'; | ||
displayName = 'n8n API'; | ||
documentationUrl = 'n8nApi'; | ||
properties: INodeProperties[] = [ | ||
{ | ||
displayName: 'API Key', | ||
name: 'apiKey', | ||
type: 'string', | ||
default: '', | ||
description: 'The API key for the n8n instance', | ||
}, | ||
{ | ||
displayName: 'Base URL', | ||
name: 'baseUrl', | ||
type: 'string', | ||
default: '', | ||
placeholder: 'https://<name>.app.n8n.cloud/api/v1', | ||
description: 'The API URL of the n8n instance', | ||
}, | ||
]; | ||
authenticate: IAuthenticateGeneric = { | ||
type: 'generic', | ||
properties: { | ||
headers: { | ||
'X-N8N-API-KEY': '={{ $credentials.apiKey }}', | ||
}, | ||
}, | ||
}; | ||
test: ICredentialTestRequest = { | ||
request: { | ||
baseURL: '={{ $credentials.baseUrl }}', | ||
url: '/workflows?limit=5', | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
import { INodeProperties } from 'n8n-workflow'; | ||
import { parseAndSetBodyJson } from './GenericFunctions'; | ||
|
||
export const credentialOperations: INodeProperties[] = [ | ||
{ | ||
displayName: 'Operation', | ||
name: 'operation', | ||
type: 'options', | ||
noDataExpression: true, | ||
default: 'create', | ||
displayOptions: { | ||
show: { | ||
resource: ['credential'], | ||
}, | ||
}, | ||
options: [ | ||
{ | ||
name: 'Create', | ||
value: 'create', | ||
action: 'Create a credential', | ||
routing: { | ||
request: { | ||
method: 'POST', | ||
url: '/credentials', | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: 'Delete', | ||
value: 'delete', | ||
action: 'Delete a credential', | ||
routing: { | ||
request: { | ||
method: 'DELETE', | ||
url: '=/credentials/{{ $parameter.credentialId }}', | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: 'Get Schema', | ||
value: 'getSchema', | ||
action: 'Get credential data schema for type', | ||
routing: { | ||
request: { | ||
method: 'GET', | ||
url: '=/credentials/schema/{{ $parameter.credentialTypeName }}', | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
const createOperation: INodeProperties[] = [ | ||
{ | ||
displayName: 'Name', | ||
name: 'name', | ||
type: 'string', | ||
default: '', | ||
placeholder: 'e.g. n8n account', | ||
required: true, | ||
displayOptions: { | ||
show: { | ||
resource: ['credential'], | ||
operation: ['create'], | ||
}, | ||
}, | ||
routing: { | ||
request: { | ||
body: { | ||
name: '={{ $value }}', | ||
}, | ||
}, | ||
}, | ||
description: 'Name of the new credential', | ||
}, | ||
{ | ||
displayName: 'Credential Type', | ||
name: 'credentialTypeName', | ||
type: 'string', | ||
placeholder: 'e.g. n8nApi', | ||
default: '', | ||
required: true, | ||
displayOptions: { | ||
show: { | ||
resource: ['credential'], | ||
operation: ['create'], | ||
}, | ||
}, | ||
routing: { | ||
request: { | ||
body: { | ||
type: '={{ $value }}', | ||
}, | ||
}, | ||
}, | ||
description: | ||
"The available types depend on nodes installed on the n8n instance. Some built-in types include e.g. 'githubApi', 'notionApi', and 'slackApi'.", | ||
}, | ||
{ | ||
displayName: 'Data', | ||
name: 'data', | ||
type: 'json', | ||
default: '', | ||
placeholder: | ||
'// e.g. for n8nApi \n{\n "apiKey": "my-n8n-api-key",\n "baseUrl": "https://<name>.app.n8n.cloud/api/v1",\n}', | ||
required: true, | ||
typeOptions: { | ||
alwaysOpenEditWindow: true, | ||
}, | ||
displayOptions: { | ||
show: { | ||
resource: ['credential'], | ||
operation: ['create'], | ||
}, | ||
}, | ||
routing: { | ||
send: { | ||
// Validate that the 'data' property is parseable as JSON and | ||
// set it into the request as body.data. | ||
preSend: [parseAndSetBodyJson('data', 'data')], | ||
}, | ||
}, | ||
description: | ||
"A valid JSON object with properties required for this Credential Type. To see the expected format, you can use 'Get Schema' operation.", | ||
}, | ||
]; | ||
|
||
const deleteOperation: INodeProperties[] = [ | ||
{ | ||
displayName: 'Credential ID', | ||
name: 'credentialId', | ||
type: 'string', | ||
required: true, | ||
default: '', | ||
displayOptions: { | ||
show: { | ||
resource: ['credential'], | ||
operation: ['delete'], | ||
}, | ||
}, | ||
}, | ||
]; | ||
|
||
const getSchemaOperation: INodeProperties[] = [ | ||
{ | ||
displayName: 'Credential Type', | ||
name: 'credentialTypeName', | ||
default: '', | ||
placeholder: 'e.g. n8nApi', | ||
required: true, | ||
type: 'string', | ||
displayOptions: { | ||
show: { | ||
resource: ['credential'], | ||
operation: ['getSchema'], | ||
}, | ||
}, | ||
description: | ||
"The available types depend on nodes installed on the n8n instance. Some built-in types include e.g. 'githubApi', 'notionApi', and 'slackApi'.", | ||
}, | ||
]; | ||
|
||
export const credentialFields: INodeProperties[] = [ | ||
...createOperation, | ||
...deleteOperation, | ||
...getSchemaOperation, | ||
]; |
Oops, something went wrong.