mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
feat(Airtable Node): Access token support (#6160)
This commit is contained in:
parent
91fee0ca66
commit
f9fd82040a
|
@ -8,6 +8,13 @@ export class AirtableApi implements ICredentialType {
|
||||||
documentationUrl = 'airtable';
|
documentationUrl = 'airtable';
|
||||||
|
|
||||||
properties: INodeProperties[] = [
|
properties: INodeProperties[] = [
|
||||||
|
{
|
||||||
|
displayName:
|
||||||
|
'API Keys will be deprecated by the end of January 2024, see <a href="https://support.airtable.com/docs/airtable-api-key-deprecation-notice" target="_blank">this article</a> for more details. We recommend to use Personal Access Token instead.',
|
||||||
|
name: 'deprecated',
|
||||||
|
type: 'notice',
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'API Key',
|
displayName: 'API Key',
|
||||||
name: 'apiKey',
|
name: 'apiKey',
|
||||||
|
|
|
@ -0,0 +1,39 @@
|
||||||
|
import type {
|
||||||
|
IAuthenticateGeneric,
|
||||||
|
ICredentialTestRequest,
|
||||||
|
ICredentialType,
|
||||||
|
INodeProperties,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export class AirtableTokenApi implements ICredentialType {
|
||||||
|
name = 'airtableTokenApi';
|
||||||
|
|
||||||
|
displayName = 'Airtable Personal Access Token API';
|
||||||
|
|
||||||
|
documentationUrl = 'airtable';
|
||||||
|
|
||||||
|
properties: INodeProperties[] = [
|
||||||
|
{
|
||||||
|
displayName: 'Access Token',
|
||||||
|
name: 'accessToken',
|
||||||
|
type: 'string',
|
||||||
|
typeOptions: { password: true },
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
authenticate: IAuthenticateGeneric = {
|
||||||
|
type: 'generic',
|
||||||
|
properties: {
|
||||||
|
headers: {
|
||||||
|
Authorization: '=Bearer {{$credentials.accessToken}}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
test: ICredentialTestRequest = {
|
||||||
|
request: {
|
||||||
|
baseURL: 'https://api.airtable.com/v0/meta/whoami',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
|
@ -27,9 +27,39 @@ export class Airtable implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'airtableApi',
|
name: 'airtableApi',
|
||||||
required: true,
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: ['airtableApi'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'airtableTokenApi',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: ['airtableTokenApi'],
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
properties: [
|
properties: [
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'API Key',
|
||||||
|
value: 'airtableApi',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Access Token',
|
||||||
|
value: 'airtableTokenApi',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'airtableApi',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Operation',
|
displayName: 'Operation',
|
||||||
name: 'operation',
|
name: 'operation',
|
||||||
|
@ -546,14 +576,15 @@ export class Airtable implements INodeType {
|
||||||
delete (row.fields as any).id;
|
delete (row.fields as any).id;
|
||||||
} else {
|
} else {
|
||||||
// Add only the specified fields
|
// Add only the specified fields
|
||||||
row.fields = {} as IDataObject;
|
const rowFields: IDataObject = {};
|
||||||
|
|
||||||
fields = this.getNodeParameter('fields', i, []) as string[];
|
fields = this.getNodeParameter('fields', i, []) as string[];
|
||||||
|
|
||||||
for (const fieldName of fields) {
|
for (const fieldName of fields) {
|
||||||
// @ts-ignore
|
rowFields[fieldName] = items[i].json[fieldName];
|
||||||
row.fields[fieldName] = items[i].json[fieldName];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
row.fields = rowFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
rows.push(row);
|
rows.push(row);
|
||||||
|
@ -761,10 +792,12 @@ export class Airtable implements INodeType {
|
||||||
} else {
|
} else {
|
||||||
fields = this.getNodeParameter('fields', i, []) as string[];
|
fields = this.getNodeParameter('fields', i, []) as string[];
|
||||||
|
|
||||||
|
const rowFields: IDataObject = {};
|
||||||
for (const fieldName of fields) {
|
for (const fieldName of fields) {
|
||||||
// @ts-ignore
|
rowFields[fieldName] = items[i].json[fieldName];
|
||||||
row.fields[fieldName] = items[i].json[fieldName];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
row.fields = rowFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
row.id = this.getNodeParameter('id', i) as string;
|
row.id = this.getNodeParameter('id', i) as string;
|
||||||
|
|
|
@ -28,12 +28,42 @@ export class AirtableTrigger implements INodeType {
|
||||||
{
|
{
|
||||||
name: 'airtableApi',
|
name: 'airtableApi',
|
||||||
required: true,
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: ['airtableApi'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'airtableTokenApi',
|
||||||
|
required: true,
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
authentication: ['airtableTokenApi'],
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
polling: true,
|
polling: true,
|
||||||
inputs: [],
|
inputs: [],
|
||||||
outputs: ['main'],
|
outputs: ['main'],
|
||||||
properties: [
|
properties: [
|
||||||
|
{
|
||||||
|
displayName: 'Authentication',
|
||||||
|
name: 'authentication',
|
||||||
|
type: 'options',
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'API Key',
|
||||||
|
value: 'airtableApi',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Access Token',
|
||||||
|
value: 'airtableTokenApi',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'airtableApi',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
displayName: 'Base',
|
displayName: 'Base',
|
||||||
name: 'baseId',
|
name: 'baseId',
|
||||||
|
@ -192,19 +222,14 @@ export class AirtableTrigger implements INodeType {
|
||||||
|
|
||||||
async poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null> {
|
async poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null> {
|
||||||
const downloadAttachments = this.getNodeParameter('downloadAttachments', 0) as boolean;
|
const downloadAttachments = this.getNodeParameter('downloadAttachments', 0) as boolean;
|
||||||
|
|
||||||
const webhookData = this.getWorkflowStaticData('node');
|
const webhookData = this.getWorkflowStaticData('node');
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields') as IDataObject;
|
||||||
|
const base = this.getNodeParameter('baseId', '', { extractValue: true }) as string;
|
||||||
|
const table = this.getNodeParameter('tableId', '', { extractValue: true }) as string;
|
||||||
|
const triggerField = this.getNodeParameter('triggerField') as string;
|
||||||
|
|
||||||
const qs: IDataObject = {};
|
const qs: IDataObject = {};
|
||||||
|
|
||||||
const additionalFields = this.getNodeParameter('additionalFields') as IDataObject;
|
|
||||||
|
|
||||||
const base = this.getNodeParameter('baseId', '', { extractValue: true }) as string;
|
|
||||||
|
|
||||||
const table = this.getNodeParameter('tableId', '', { extractValue: true }) as string;
|
|
||||||
|
|
||||||
const triggerField = this.getNodeParameter('triggerField') as string;
|
|
||||||
|
|
||||||
const endpoint = `${base}/${table}`;
|
const endpoint = `${base}/${table}`;
|
||||||
|
|
||||||
const now = moment().utc().format();
|
const now = moment().utc().format();
|
||||||
|
|
|
@ -58,8 +58,8 @@ export async function apiRequest(
|
||||||
if (Object.keys(body).length === 0) {
|
if (Object.keys(body).length === 0) {
|
||||||
delete options.body;
|
delete options.body;
|
||||||
}
|
}
|
||||||
|
const authenticationMethod = this.getNodeParameter('authentication', 0) as string;
|
||||||
return this.helpers.requestWithAuthentication.call(this, 'airtableApi', options);
|
return this.helpers.requestWithAuthentication.call(this, authenticationMethod, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
"dist/credentials/AffinityApi.credentials.js",
|
"dist/credentials/AffinityApi.credentials.js",
|
||||||
"dist/credentials/AgileCrmApi.credentials.js",
|
"dist/credentials/AgileCrmApi.credentials.js",
|
||||||
"dist/credentials/AirtableApi.credentials.js",
|
"dist/credentials/AirtableApi.credentials.js",
|
||||||
|
"dist/credentials/AirtableTokenApi.credentials.js",
|
||||||
"dist/credentials/Amqp.credentials.js",
|
"dist/credentials/Amqp.credentials.js",
|
||||||
"dist/credentials/ApiTemplateIoApi.credentials.js",
|
"dist/credentials/ApiTemplateIoApi.credentials.js",
|
||||||
"dist/credentials/AsanaApi.credentials.js",
|
"dist/credentials/AsanaApi.credentials.js",
|
||||||
|
|
Loading…
Reference in a new issue