2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2023-03-09 09:13:15 -08:00
|
|
|
IExecuteFunctions,
|
2023-01-27 03:22:44 -08:00
|
|
|
IDataObject,
|
|
|
|
INodeExecutionData,
|
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
|
|
|
} from 'n8n-workflow';
|
2022-08-17 08:50:24 -07:00
|
|
|
import { upleadApiRequest } from './GenericFunctions';
|
|
|
|
import { companyFields, companyOperations } from './CompanyDesciption';
|
|
|
|
import { personFields, personOperations } from './PersonDescription';
|
2020-01-28 10:51:49 -08:00
|
|
|
|
|
|
|
export class Uplead implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
displayName: 'Uplead',
|
|
|
|
name: 'uplead',
|
2022-06-20 07:54:01 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
2020-01-28 10:51:49 -08:00
|
|
|
icon: 'file:uplead.png',
|
|
|
|
group: ['output'],
|
|
|
|
version: 1,
|
|
|
|
subtitle: '={{$parameter["operation"] + ":" + $parameter["resource"]}}',
|
|
|
|
description: 'Consume Uplead API',
|
|
|
|
defaults: {
|
|
|
|
name: 'Uplead',
|
|
|
|
},
|
|
|
|
inputs: ['main'],
|
|
|
|
outputs: ['main'],
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'upleadApi',
|
|
|
|
required: true,
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2020-01-28 10:51:49 -08:00
|
|
|
],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Resource',
|
|
|
|
name: 'resource',
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
noDataExpression: true,
|
2020-01-28 10:51:49 -08:00
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'Company',
|
|
|
|
value: 'company',
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
|
|
|
'Company API lets you lookup company data via a domain name or company name',
|
2020-01-28 10:51:49 -08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Person',
|
|
|
|
value: 'person',
|
2022-08-17 08:50:24 -07:00
|
|
|
description:
|
|
|
|
'Person API lets you lookup a person based on an email address OR based on a domain name + first name + last name',
|
2020-01-28 10:51:49 -08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
default: 'company',
|
|
|
|
},
|
|
|
|
...companyOperations,
|
|
|
|
...companyFields,
|
|
|
|
...personOperations,
|
|
|
|
...personFields,
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
const items = this.getInputData();
|
|
|
|
const returnData: IDataObject[] = [];
|
2022-04-22 09:29:51 -07:00
|
|
|
const length = items.length;
|
2020-01-28 10:51:49 -08:00
|
|
|
const qs: IDataObject = {};
|
|
|
|
let responseData;
|
2022-12-02 03:53:59 -08:00
|
|
|
const resource = this.getNodeParameter('resource', 0);
|
|
|
|
const operation = this.getNodeParameter('operation', 0);
|
2020-01-28 10:51:49 -08:00
|
|
|
for (let i = 0; i < length; i++) {
|
2021-07-19 23:58:54 -07:00
|
|
|
try {
|
|
|
|
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);
|
2020-01-28 10:51:49 -08:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
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);
|
2020-01-28 10:51:49 -08:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
}
|
|
|
|
if (Array.isArray(responseData.data)) {
|
|
|
|
returnData.push.apply(returnData, responseData.data as IDataObject[]);
|
|
|
|
} else {
|
|
|
|
if (responseData.data !== null) {
|
|
|
|
returnData.push(responseData.data as IDataObject);
|
2020-01-28 10:51:49 -08:00
|
|
|
}
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
} catch (error) {
|
2024-06-19 22:45:00 -07:00
|
|
|
if (this.continueOnFail(error)) {
|
2021-07-19 23:58:54 -07:00
|
|
|
returnData.push({ error: error.message });
|
|
|
|
continue;
|
2020-07-13 08:28:56 -07:00
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
throw error;
|
2020-01-28 10:51:49 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return [this.helpers.returnJsonArray(returnData)];
|
|
|
|
}
|
|
|
|
}
|