n8n-nodes-apolloio
Version:
n8n node for Apollo.io - Search, Enrich, and Prospect People & Organizations via API
151 lines • 6.95 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.enrichPerson = enrichPerson;
exports.bulkEnrichPeople = bulkEnrichPeople;
exports.searchPeople = searchPeople;
const n8n_workflow_1 = require("n8n-workflow");
const transport_1 = require("../transport");
const utils_1 = require("../utils");
async function enrichPerson() {
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
const email = this.getNodeParameter('personEmail', i);
const linkedinUrl = this.getNodeParameter('personLinkedInUrl', i);
const personId = this.getNodeParameter('personId', i);
const firstName = this.getNodeParameter('personFirstName', i);
const lastName = this.getNodeParameter('personLastName', i);
const domain = this.getNodeParameter('personDomain', i);
const revealPersonalEmails = this.getNodeParameter('revealPersonalEmails', i);
const revealPhoneNumber = this.getNodeParameter('revealPhoneNumber', i);
const webhookUrl = this.getNodeParameter('webhookUrl', i);
if (revealPhoneNumber && !webhookUrl) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Webhook URL is required when Reveal Phone Number is set to true', { itemIndex: i });
}
if (!email && !linkedinUrl && !personId && !(firstName && lastName && domain)) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Missing required identifier fields', {
itemIndex: i,
});
}
const body = {};
if (email)
body.email = email;
if (linkedinUrl)
body.linkedin_url = linkedinUrl;
if (personId)
body.id = personId;
if (firstName)
body.first_name = firstName;
if (lastName)
body.last_name = lastName;
if (domain)
body.domain = domain;
if (revealPersonalEmails)
body.reveal_personal_emails = revealPersonalEmails;
if (revealPhoneNumber)
body.reveal_phone_number = revealPhoneNumber;
if (webhookUrl)
body.webhook_url = webhookUrl;
const response = await transport_1.apiRequest.call(this, 'POST', '/people/match', body);
returnData.push({ json: response.person });
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message } });
continue;
}
throw error;
}
}
return returnData;
}
async function bulkEnrichPeople() {
const peopleJson = this.getNodeParameter('peopleDetailsJson', 0);
let peopleArray;
try {
peopleArray = JSON.parse(peopleJson);
}
catch {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Invalid JSON for people details');
}
if (!Array.isArray(peopleArray) || peopleArray.length < 1 || peopleArray.length > 10) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'People details array must contain 1 to 10 items');
}
const response = await transport_1.apiRequest.call(this, 'POST', '/people/bulk_match', {
details: peopleArray,
});
return this.helpers.returnJsonArray(response.people);
}
async function searchPeople() {
const items = this.getInputData();
const returnData = [];
for (let i = 0; i < items.length; i++) {
try {
const personTitles = this.getNodeParameter('personTitles', i);
const qKeywords = this.getNodeParameter('qKeywords', i);
const personLocations = this.getNodeParameter('personLocations', i);
const personSeniorities = this.getNodeParameter('personSeniorities', i);
const organizationLocations = this.getNodeParameter('organizationLocations', i);
const organizationDomains = this.getNodeParameter('organizationDomains', i);
const contactEmailStatus = this.getNodeParameter('contactEmailStatus', i);
const organizationIds = this.getNodeParameter('organizationIds', i);
const organizationNumEmployeesRanges = this.getNodeParameter('organizationNumEmployeesRanges', i);
const revenueRangeMin = this.getNodeParameter('revenueRangeMin', i);
const revenueRangeMax = this.getNodeParameter('revenueRangeMax', i);
const page = this.getNodeParameter('page', i);
const perPage = this.getNodeParameter('perPage', i);
const body = {
page,
per_page: perPage,
};
if (personTitles) {
body.person_titles = (0, utils_1.splitAndTrim)(personTitles);
}
if (qKeywords) {
body.q_keywords = qKeywords;
}
if (personLocations) {
body.person_locations = (0, utils_1.splitAndTrim)(personLocations);
}
if (personSeniorities && personSeniorities.length > 0) {
body.person_seniorities = personSeniorities;
}
if (organizationLocations) {
body.organization_locations = (0, utils_1.splitAndTrim)(organizationLocations);
}
if (organizationDomains) {
body.q_organization_domains_list = (0, utils_1.splitAndTrim)(organizationDomains);
}
if (contactEmailStatus && contactEmailStatus.length > 0) {
body.contact_email_status = contactEmailStatus;
}
if (organizationIds) {
body.organization_ids = (0, utils_1.splitAndTrim)(organizationIds);
}
if (organizationNumEmployeesRanges) {
body.organization_num_employees_ranges = (0, utils_1.splitAndTrim)(organizationNumEmployeesRanges);
}
if (revenueRangeMin) {
body.revenue_range = { ...body.revenue_range, min: revenueRangeMin };
}
if (revenueRangeMax) {
body.revenue_range = { ...body.revenue_range, max: revenueRangeMax };
}
const response = await transport_1.apiRequest.call(this, 'POST', '/mixed_people/api_search', body);
const people = (response === null || response === void 0 ? void 0 : response.people) || [];
for (const person of people) {
returnData.push({ json: person });
}
}
catch (error) {
if (this.continueOnFail()) {
returnData.push({ json: { error: error.message } });
continue;
}
throw error;
}
}
return returnData;
}
//# sourceMappingURL=Person.js.map