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';
|
2024-08-29 06:55:53 -07:00
|
|
|
|
import { NodeConnectionType } from 'n8n-workflow';
|
2021-03-23 16:20:48 -07:00
|
|
|
|
|
2022-08-01 13:47:55 -07:00
|
|
|
|
import { clearbitApiRequest } from './GenericFunctions';
|
2021-03-23 16:20:48 -07:00
|
|
|
|
|
2022-08-01 13:47:55 -07:00
|
|
|
|
import { companyFields, companyOperations } from './CompanyDescription';
|
2021-03-23 16:20:48 -07:00
|
|
|
|
|
2022-08-01 13:47:55 -07:00
|
|
|
|
import { personFields, personOperations } from './PersonDescription';
|
2020-01-26 20:27:14 -08:00
|
|
|
|
|
|
|
|
|
export class Clearbit implements INodeType {
|
|
|
|
|
description: INodeTypeDescription = {
|
|
|
|
|
displayName: 'Clearbit',
|
|
|
|
|
name: 'clearbit',
|
2021-03-23 16:20:48 -07:00
|
|
|
|
icon: 'file:clearbit.svg',
|
2020-01-26 20:27:14 -08:00
|
|
|
|
group: ['output'],
|
|
|
|
|
version: 1,
|
|
|
|
|
subtitle: '={{$parameter["operation"] + ":" + $parameter["resource"]}}',
|
|
|
|
|
description: 'Consume Clearbit API',
|
|
|
|
|
defaults: {
|
|
|
|
|
name: 'Clearbit',
|
|
|
|
|
},
|
2024-08-29 06:55:53 -07:00
|
|
|
|
inputs: [NodeConnectionType.Main],
|
|
|
|
|
outputs: [NodeConnectionType.Main],
|
2020-01-26 20:27:14 -08:00
|
|
|
|
credentials: [
|
|
|
|
|
{
|
|
|
|
|
name: 'clearbitApi',
|
|
|
|
|
required: true,
|
2020-10-22 06:46:03 -07:00
|
|
|
|
},
|
2020-01-26 20:27:14 -08:00
|
|
|
|
],
|
|
|
|
|
properties: [
|
|
|
|
|
{
|
|
|
|
|
displayName: 'Resource',
|
|
|
|
|
name: 'resource',
|
|
|
|
|
type: 'options',
|
2022-05-20 14:47:24 -07:00
|
|
|
|
noDataExpression: true,
|
2020-01-26 20:27:14 -08:00
|
|
|
|
options: [
|
|
|
|
|
{
|
|
|
|
|
name: 'Company',
|
|
|
|
|
value: 'company',
|
|
|
|
|
description: 'The Company API allows you to look up a company by their domain',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: 'Person',
|
|
|
|
|
value: 'person',
|
2022-08-01 13:47:55 -07:00
|
|
|
|
description:
|
|
|
|
|
'The Person API lets you retrieve social information associated with an email address, such as a person’s name, location and Twitter handle',
|
2020-01-26 20:27:14 -08:00
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
default: 'company',
|
|
|
|
|
},
|
|
|
|
|
...companyOperations,
|
|
|
|
|
...companyFields,
|
|
|
|
|
...personOperations,
|
|
|
|
|
...personFields,
|
|
|
|
|
],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
|
|
|
|
|
const items = this.getInputData();
|
2022-08-30 08:55:33 -07:00
|
|
|
|
const returnData: INodeExecutionData[] = [];
|
2022-04-22 09:29:51 -07:00
|
|
|
|
const length = items.length;
|
2020-01-26 20:27:14 -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-26 20:27:14 -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;
|
2022-11-18 07:29:44 -08:00
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
qs.email = email;
|
|
|
|
|
if (additionalFields.givenName) {
|
|
|
|
|
qs.given_name = additionalFields.givenName as string;
|
|
|
|
|
}
|
|
|
|
|
if (additionalFields.familyName) {
|
|
|
|
|
qs.family_name = additionalFields.familyName as string;
|
|
|
|
|
}
|
|
|
|
|
if (additionalFields.ipAddress) {
|
|
|
|
|
qs.ip_address = additionalFields.ipAddress as string;
|
|
|
|
|
}
|
|
|
|
|
if (additionalFields.location) {
|
|
|
|
|
qs.location = additionalFields.location as string;
|
|
|
|
|
}
|
|
|
|
|
if (additionalFields.company) {
|
|
|
|
|
qs.company = additionalFields.company as string;
|
|
|
|
|
}
|
|
|
|
|
if (additionalFields.companyDomain) {
|
|
|
|
|
qs.company_domain = additionalFields.companyDomain as string;
|
|
|
|
|
}
|
|
|
|
|
if (additionalFields.linkedIn) {
|
|
|
|
|
qs.linkedin = additionalFields.linkedIn as string;
|
|
|
|
|
}
|
|
|
|
|
if (additionalFields.twitter) {
|
|
|
|
|
qs.twitter = additionalFields.twitter as string;
|
|
|
|
|
}
|
|
|
|
|
if (additionalFields.facebook) {
|
|
|
|
|
qs.facebook = additionalFields.facebook as string;
|
|
|
|
|
}
|
2022-08-01 13:47:55 -07:00
|
|
|
|
responseData = await clearbitApiRequest.call(
|
|
|
|
|
this,
|
|
|
|
|
'GET',
|
|
|
|
|
`${resource}-stream`,
|
|
|
|
|
'/v2/people/find',
|
|
|
|
|
{},
|
|
|
|
|
qs,
|
|
|
|
|
);
|
2020-01-26 20:27:14 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
|
if (resource === 'company') {
|
|
|
|
|
if (operation === 'enrich') {
|
|
|
|
|
const domain = this.getNodeParameter('domain', i) as string;
|
2022-11-18 07:29:44 -08:00
|
|
|
|
const additionalFields = this.getNodeParameter('additionalFields', i);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
qs.domain = domain;
|
|
|
|
|
if (additionalFields.companyName) {
|
|
|
|
|
qs.company_name = additionalFields.companyName as string;
|
|
|
|
|
}
|
|
|
|
|
if (additionalFields.linkedin) {
|
|
|
|
|
qs.linkedin = additionalFields.linkedin as string;
|
|
|
|
|
}
|
|
|
|
|
if (additionalFields.twitter) {
|
|
|
|
|
qs.twitter = additionalFields.twitter as string;
|
|
|
|
|
}
|
|
|
|
|
if (additionalFields.facebook) {
|
|
|
|
|
qs.facebook = additionalFields.facebook as string;
|
|
|
|
|
}
|
2022-08-01 13:47:55 -07:00
|
|
|
|
responseData = await clearbitApiRequest.call(
|
|
|
|
|
this,
|
|
|
|
|
'GET',
|
|
|
|
|
`${resource}-stream`,
|
|
|
|
|
'/v2/companies/find',
|
|
|
|
|
{},
|
|
|
|
|
qs,
|
|
|
|
|
);
|
2020-01-26 20:27:14 -08:00
|
|
|
|
}
|
2021-07-19 23:58:54 -07:00
|
|
|
|
if (operation === 'autocomplete') {
|
|
|
|
|
const name = this.getNodeParameter('name', i) as string;
|
|
|
|
|
qs.query = name;
|
2022-08-01 13:47:55 -07:00
|
|
|
|
responseData = await clearbitApiRequest.call(
|
|
|
|
|
this,
|
|
|
|
|
'GET',
|
|
|
|
|
'autocomplete',
|
|
|
|
|
'/v1/companies/suggest',
|
|
|
|
|
{},
|
|
|
|
|
qs,
|
|
|
|
|
);
|
2020-01-26 20:27:14 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-08-30 08:55:33 -07:00
|
|
|
|
const executionData = this.helpers.constructExecutionMetaData(
|
2023-02-27 19:39:43 -08:00
|
|
|
|
this.helpers.returnJsonArray(responseData as IDataObject),
|
2022-08-30 08:55:33 -07:00
|
|
|
|
{ itemData: { item: i } },
|
|
|
|
|
);
|
|
|
|
|
returnData.push(...executionData);
|
2021-07-19 23:58:54 -07:00
|
|
|
|
} catch (error) {
|
2024-08-30 00:59:30 -07:00
|
|
|
|
if (this.continueOnFail()) {
|
2022-08-30 08:55:33 -07:00
|
|
|
|
returnData.push({ error: error.message, json: {} });
|
2021-07-19 23:58:54 -07:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
throw error;
|
2020-01-26 20:27:14 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-05 03:59:02 -07:00
|
|
|
|
return [returnData];
|
2020-01-26 20:27:14 -08:00
|
|
|
|
}
|
|
|
|
|
}
|