Uplead node

This commit is contained in:
Ricardo Espinoza 2020-01-28 13:51:49 -05:00
parent 4b7074a686
commit 1428895d53
7 changed files with 336 additions and 0 deletions

View file

@ -0,0 +1,17 @@
import {
ICredentialType,
NodePropertyTypes,
} from 'n8n-workflow';
export class UpleadApi implements ICredentialType {
name = 'upleadApi';
displayName = 'Uplead API';
properties = [
{
displayName: 'API Key',
name: 'apiKey',
type: 'string' as NodePropertyTypes,
default: '',
},
];
}

View file

@ -0,0 +1,65 @@
import { INodeProperties } from 'n8n-workflow';
export const companyOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'company',
],
},
},
options: [
{
name: 'Enrich',
value: 'enrich',
},
],
default: 'enrich',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const companyFields = [
/* -------------------------------------------------------------------------- */
/* company:enrich */
/* -------------------------------------------------------------------------- */
{
displayName: 'Company',
name: 'company',
type: 'string',
default: '',
displayOptions: {
show: {
resource: [
'company',
],
operation: [
'enrich',
],
},
},
description: 'the name of the company (e.g amazon)',
},
{
displayName: 'Domain',
name: 'domain',
type: 'string',
default: '',
displayOptions: {
show: {
resource: [
'company',
],
operation: [
'enrich',
],
},
},
description: 'the domain name (e.g amazon.com)',
},
] as INodeProperties[];

View file

@ -0,0 +1,32 @@
import { OptionsWithUri } from 'request';
import {
IExecuteFunctions,
IExecuteSingleFunctions,
IHookFunctions,
ILoadOptionsFunctions,
} from 'n8n-core';
import { IDataObject } from 'n8n-workflow';
export async function upleadApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
const credentials = this.getCredentials('upleadApi');
if (credentials === undefined) {
throw new Error('No credentials got returned!');
}
let options: OptionsWithUri = {
headers: { Authorization: credentials.apiKey },
method,
qs,
body,
uri: uri ||`https://api.uplead.com/v2${resource}`,
json: true
};
options = Object.assign({}, options, option);
if (Object.keys(options.body).length === 0) {
delete options.body;
}
try {
return await this.helpers.request!(options);
} catch (err) {
throw new Error(err);
}
}

View file

@ -0,0 +1,99 @@
import { INodeProperties } from 'n8n-workflow';
export const personOperations = [
{
displayName: 'Operation',
name: 'operation',
type: 'options',
displayOptions: {
show: {
resource: [
'person',
],
},
},
options: [
{
name: 'Enrich',
value: 'enrich',
},
],
default: 'enrich',
description: 'The operation to perform.',
},
] as INodeProperties[];
export const personFields = [
/* -------------------------------------------------------------------------- */
/* person:enrich */
/* -------------------------------------------------------------------------- */
{
displayName: 'Email',
name: 'email',
type: 'string',
default: '',
displayOptions: {
show: {
resource: [
'person',
],
operation: [
'enrich',
],
},
},
description: 'email address (e.g mbenioff@salesforce.com)',
},
{
displayName: 'Fist Name',
name: 'firstname',
type: 'string',
default: '',
displayOptions: {
show: {
resource: [
'person',
],
operation: [
'enrich',
],
},
},
description: 'first name of the person (e.g Marc)',
},
{
displayName: 'Last Name',
name: 'lastname',
type: 'string',
default: '',
displayOptions: {
show: {
resource: [
'person',
],
operation: [
'enrich',
],
},
},
description: 'Last name of the person (e.g Benioff)',
},
{
displayName: 'Domain',
name: 'domain',
type: 'string',
default: '',
displayOptions: {
show: {
resource: [
'person',
],
operation: [
'enrich',
],
},
},
description: 'The domain name (e.g salesforce.com)',
},
] as INodeProperties[];

View file

@ -0,0 +1,121 @@
import {
IExecuteFunctions,
} from 'n8n-core';
import {
IDataObject,
INodeExecutionData,
INodeType,
INodeTypeDescription,
} from 'n8n-workflow';
import {
upleadApiRequest,
} from './GenericFunctions';
import {
companyFields,
companyOperations,
} from './CompanyDesciption';
import {
personOperations,
personFields,
} from './PersonDescription';
export class Uplead implements INodeType {
description: INodeTypeDescription = {
displayName: 'Uplead',
name: 'uplead',
icon: 'file:uplead.png',
group: ['output'],
version: 1,
subtitle: '={{$parameter["operation"] + ":" + $parameter["resource"]}}',
description: 'Consume Uplead API',
defaults: {
name: 'Uplead',
color: '#5d6f7b',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'upleadApi',
required: true,
}
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
options: [
{
name: 'Company',
value: 'company',
description: 'Company API lets you lookup company data via a domain name or company name.',
},
{
name: 'Person',
value: 'person',
description: `Person API lets you lookup a person based on an email address OR based on a domain name + first name + last name`
},
],
default: 'company',
description: 'Resource to consume.',
},
...companyOperations,
...companyFields,
...personOperations,
...personFields,
],
};
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const length = items.length as unknown as number;
const qs: IDataObject = {};
let responseData;
const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
for (let i = 0; i < length; i++) {
if (resource === 'person') {
if (operation === 'enrich') {
const email = this.getNodeParameter('email', i) as string;
const firstname = this.getNodeParameter('firstname', i) as string;
const lastname = this.getNodeParameter('lastname', i) as string;
const domain = this.getNodeParameter('domain', i) as string;
if (email) {
qs.email = email;
}
if (firstname) {
qs.first_name = firstname;
}
if (lastname) {
qs.last_name = lastname;
}
if (domain) {
qs.domain = domain;
}
responseData = await upleadApiRequest.call(this, 'GET', '/person-search', {}, qs);
}
}
if (resource === 'company') {
if (operation === 'enrich') {
const domain = this.getNodeParameter('domain', i) as string;
const company = this.getNodeParameter('company', i) as string;
if (domain) {
qs.domain = domain;
}
if (company) {
qs.company = company;
}
responseData = await upleadApiRequest.call(this, 'GET', '/company-search', {}, qs);
}
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else {
returnData.push(responseData as IDataObject);
}
}
return [this.helpers.returnJsonArray(returnData)];
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

View file

@ -85,6 +85,7 @@
"dist/credentials/TwilioApi.credentials.js",
"dist/credentials/TypeformApi.credentials.js",
"dist/credentials/TogglApi.credentials.js",
"dist/credentials/UpleadApi.credentials.js",
"dist/credentials/VeroApi.credentials.js",
"dist/credentials/WebflowApi.credentials.js",
"dist/credentials/WordpressApi.credentials.js",
@ -190,6 +191,7 @@
"dist/nodes/Trello/TrelloTrigger.node.js",
"dist/nodes/Twilio/Twilio.node.js",
"dist/nodes/Typeform/TypeformTrigger.node.js",
"dist/nodes/Uplead/Uplead.node.js",
"dist/nodes/Vero/Vero.node.js",
"dist/nodes/Webflow/WebflowTrigger.node.js",
"dist/nodes/Webhook.node.js",