n8n/packages/nodes-base/nodes/Intercom/Intercom.node.ts

558 lines
18 KiB
TypeScript
Raw Normal View History

2019-11-15 12:10:51 -08:00
import {
2019-11-18 13:41:00 -08:00
IExecuteFunctions,
2019-11-15 12:10:51 -08:00
} from 'n8n-core';
import {
IDataObject,
ILoadOptionsFunctions,
INodeExecutionData,
2019-11-15 12:10:51 -08:00
INodePropertyOptions,
INodeType,
INodeTypeDescription,
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
NodeApiError,
NodeOperationError,
2019-11-15 12:10:51 -08:00
} from 'n8n-workflow';
2019-11-16 14:16:11 -08:00
import {
leadFields,
leadOpeations,
2019-11-16 14:16:11 -08:00
} from './LeadDescription';
import {
intercomApiRequest,
intercomApiRequestAllItems,
2019-11-16 15:47:28 -08:00
validateJSON,
2019-11-16 14:16:11 -08:00
} from './GenericFunctions';
2019-11-16 15:47:28 -08:00
import {
IAvatar,
2019-11-16 15:47:28 -08:00
ILead,
2019-11-21 09:39:04 -08:00
ILeadCompany,
} from './LeadInterface';
import {
userFields,
userOpeations,
} from './UserDescription';
import {
IUser,
IUserCompany,
} from './UserInterface';
import {
companyFields,
companyOperations,
} from './CompanyDescription';
2019-11-21 09:39:04 -08:00
import { ICompany } from './CompanyInteface';
2019-11-15 12:10:51 -08:00
export class Intercom implements INodeType {
description: INodeTypeDescription = {
displayName: 'Intercom',
name: 'intercom',
icon: 'file:intercom.png',
group: ['output'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Consume intercom API',
defaults: {
name: 'Intercom',
2020-01-27 06:24:54 -08:00
color: '#0575f3',
2019-11-15 12:10:51 -08:00
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'intercomApi',
required: true,
2020-10-22 06:46:03 -07:00
},
2019-11-15 12:10:51 -08:00
],
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
options: [
2019-11-21 09:39:04 -08:00
{
name: 'Company',
value: 'company',
description: 'Companies allow you to represent commercial organizations using your product.',
2019-11-21 09:39:04 -08:00
},
2019-11-15 12:10:51 -08:00
{
name: 'Lead',
value: 'lead',
2019-11-21 09:39:04 -08:00
description: 'Leads are useful for representing logged-out users of your application.',
},
{
name: 'User',
value: 'user',
description: 'The Users resource is the primary way of interacting with Intercom',
2019-11-15 12:10:51 -08:00
},
],
default: 'user',
2019-11-15 12:10:51 -08:00
description: 'Resource to consume.',
},
2019-11-16 14:16:11 -08:00
...leadOpeations,
2019-11-21 09:39:04 -08:00
...userOpeations,
...companyOperations,
2019-11-21 09:39:04 -08:00
...userFields,
2019-11-16 14:16:11 -08:00
...leadFields,
2019-11-21 09:39:04 -08:00
...companyFields,
2019-11-15 12:10:51 -08:00
],
};
2019-11-16 14:16:11 -08:00
methods = {
loadOptions: {
// Get all the available companies to display them to user so that he can
// select them easily
async getCompanies(this: ILoadOptionsFunctions): Promise<INodePropertyOptions[]> {
const returnData: INodePropertyOptions[] = [];
let companies, response;
try {
response = await intercomApiRequest.call(this, '/companies', 'GET');
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeApiError(this.getNode(), error);
2019-11-16 14:16:11 -08:00
}
companies = response.companies;
for (const company of companies) {
const companyName = company.name;
2019-11-16 15:47:28 -08:00
const companyId = company.company_id;
2019-11-16 14:16:11 -08:00
returnData.push({
name: companyName,
value: companyId,
});
}
return returnData;
2019-11-21 09:39:04 -08:00
},
2019-11-16 14:16:11 -08:00
},
};
2019-11-18 13:41:00 -08:00
async execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData();
const returnData: IDataObject[] = [];
const length = items.length as unknown as number;
let qs: IDataObject;
2019-11-18 13:41:00 -08:00
let responseData;
for (let i = 0; i < length; i++) {
qs = {};
2019-11-18 13:41:00 -08:00
const resource = this.getNodeParameter('resource', 0) as string;
2019-11-20 06:45:58 -08:00
const operation = this.getNodeParameter('operation', 0) as string;
2019-11-21 09:39:04 -08:00
//https://developers.intercom.com/intercom-api-reference/reference#leads
2019-11-18 13:41:00 -08:00
if (resource === 'lead') {
2019-11-20 06:45:58 -08:00
if (operation === 'create' || operation === 'update') {
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
2019-11-18 13:41:00 -08:00
const jsonActive = this.getNodeParameter('jsonParameters', i) as boolean;
2019-11-21 09:39:04 -08:00
const body: ILead = {};
if (operation === 'create') {
2019-11-21 09:39:04 -08:00
body.email = this.getNodeParameter('email', i) as string;
}
if (additionalFields.email) {
body.email = additionalFields.email as string;
2019-11-18 13:41:00 -08:00
}
if (additionalFields.phone) {
body.phone = additionalFields.phone as string;
2019-11-18 13:41:00 -08:00
}
if (additionalFields.name) {
body.name = additionalFields.name as string;
2019-11-18 13:41:00 -08:00
}
if (additionalFields.unsubscribedFromEmails) {
body.unsubscribed_from_emails = additionalFields.unsubscribedFromEmails as boolean;
2019-11-18 13:41:00 -08:00
}
if (additionalFields.updateLastRequestAt) {
body.update_last_request_at = additionalFields.updateLastRequestAt as boolean;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.utmSource) {
body.utm_source = additionalFields.utmSource as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.utmMedium) {
body.utm_medium = additionalFields.utmMedium as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.utmCampaign) {
body.utm_campaign = additionalFields.utmCampaign as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.utmTerm) {
body.utm_term = additionalFields.utmTerm as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.utmContent) {
body.utm_content = additionalFields.utmContent as string;
}
if (additionalFields.avatar) {
2019-11-21 09:39:04 -08:00
const avatar: IAvatar = {
type: 'avatar',
image_url: additionalFields.avatar as string,
2019-11-21 09:39:04 -08:00
};
body.avatar = avatar;
}
if (additionalFields.companies) {
2019-11-18 13:41:00 -08:00
const companies: ILeadCompany[] = [];
// @ts-ignore
additionalFields.companies.forEach(o => {
2019-11-18 13:41:00 -08:00
const company: ILeadCompany = {};
company.company_id = o;
companies.push(company);
});
body.companies = companies;
}
if (!jsonActive) {
const customAttributesValues = (this.getNodeParameter('customAttributesUi', i) as IDataObject).customAttributesValues as IDataObject[];
if (customAttributesValues) {
const customAttributes = {};
for (let i = 0; i < customAttributesValues.length; i++) {
// @ts-ignore
customAttributes[customAttributesValues[i].name] = customAttributesValues[i].value;
}
body.custom_attributes = customAttributes;
}
} else {
const customAttributesJson = validateJSON(this.getNodeParameter('customAttributesJson', i) as string);
if (customAttributesJson) {
body.custom_attributes = customAttributesJson;
2019-11-16 15:47:28 -08:00
}
}
2019-11-20 06:45:58 -08:00
if (operation === 'update') {
const updateBy = this.getNodeParameter('updateBy', 0) as string;
const value = this.getNodeParameter('value', i) as string;
if (updateBy === 'userId') {
body.user_id = value;
}
if (updateBy === 'id') {
body.id = value;
}
}
2019-11-18 13:41:00 -08:00
try {
responseData = await intercomApiRequest.call(this, '/contacts', 'POST', body);
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeApiError(this.getNode(), error);
2019-11-16 15:47:28 -08:00
}
}
if (operation === 'get') {
const selectBy = this.getNodeParameter('selectBy', 0) as string;
2019-11-21 09:39:04 -08:00
const value = this.getNodeParameter('value', i) as string;
if (selectBy === 'email') {
qs.email = value;
2019-11-21 09:39:04 -08:00
}
if (selectBy === 'userId') {
qs.user_id = value;
2019-11-21 09:39:04 -08:00
}
if (selectBy === 'phone') {
qs.phone = value;
2019-11-21 09:39:04 -08:00
}
try {
if (selectBy === 'id') {
responseData = await intercomApiRequest.call(this, `/contacts/${value}`, 'GET');
} else {
responseData = await intercomApiRequest.call(this, '/contacts', 'GET', {}, qs);
responseData = responseData.contacts;
}
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeApiError(this.getNode(), error);
2019-11-21 09:39:04 -08:00
}
}
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const filters = this.getNodeParameter('filters', i) as IDataObject;
Object.assign(qs, filters);
2019-11-21 09:39:04 -08:00
try {
if (returnAll === true) {
responseData = await intercomApiRequestAllItems.call(this, 'contacts', '/contacts', 'GET', {}, qs);
} else {
qs.per_page = this.getNodeParameter('limit', i) as number;
responseData = await intercomApiRequest.call(this, '/contacts', 'GET', {}, qs);
responseData = responseData.contacts;
}
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeApiError(this.getNode(), error);
2019-11-21 09:39:04 -08:00
}
}
if (operation === 'delete') {
const deleteBy = this.getNodeParameter('deleteBy', 0) as string;
const value = this.getNodeParameter('value', i) as string;
try {
if (deleteBy === 'id') {
responseData = await intercomApiRequest.call(this, `/contacts/${value}`, 'DELETE');
} else {
qs.user_id = value;
responseData = await intercomApiRequest.call(this, '/contacts', 'DELETE', {}, qs);
2019-11-21 09:39:04 -08:00
}
} catch (error) {
throw new NodeApiError(this.getNode(), error);
}
2019-11-21 09:39:04 -08:00
}
}
//https://developers.intercom.com/intercom-api-reference/reference#users
if (resource === 'user') {
if (operation === 'create' || operation === 'update') {
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
2019-11-21 09:39:04 -08:00
const jsonActive = this.getNodeParameter('jsonParameters', i) as boolean;
const body: IUser = {};
if (operation === 'create') {
const identifierType = this.getNodeParameter('identifierType', i) as string;
if (identifierType === 'email') {
body.email = this.getNodeParameter('idValue', i) as string;
} else if (identifierType === 'userId') {
body.user_id = this.getNodeParameter('idValue', i) as string;
}
2019-11-21 09:39:04 -08:00
}
if (additionalFields.email) {
body.email = additionalFields.email as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.userId) {
body.user_id = additionalFields.userId as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.phone) {
body.phone = additionalFields.phone as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.name) {
body.name = additionalFields.name as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.unsubscribedFromEmails) {
body.unsubscribed_from_emails = additionalFields.unsubscribedFromEmails as boolean;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.updateLastRequestAt) {
body.update_last_request_at = additionalFields.updateLastRequestAt as boolean;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.sessionCount) {
body.session_count = additionalFields.sessionCount as number;
}
if (additionalFields.avatar) {
2019-11-21 09:39:04 -08:00
const avatar: IAvatar = {
type: 'avatar',
image_url: additionalFields.avatar as string,
2019-11-21 09:39:04 -08:00
};
body.avatar = avatar;
}
if (additionalFields.utmSource) {
body.utm_source = additionalFields.utmSource as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.utmMedium) {
body.utm_medium = additionalFields.utmMedium as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.utmCampaign) {
body.utm_campaign = additionalFields.utmCampaign as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.utmTerm) {
body.utm_term = additionalFields.utmTerm as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.utmContent) {
body.utm_content = additionalFields.utmContent as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.companies) {
2019-11-21 09:39:04 -08:00
const companies: IUserCompany[] = [];
// @ts-ignore
additionalFields.companies.forEach(o => {
2019-11-21 09:39:04 -08:00
const company: IUserCompany = {};
company.company_id = o;
companies.push(company);
});
body.companies = companies;
}
if (additionalFields.sessionCount) {
body.session_count = additionalFields.sessionCount as number;
2019-11-21 09:39:04 -08:00
}
if (!jsonActive) {
const customAttributesValues = (this.getNodeParameter('customAttributesUi', i) as IDataObject).customAttributesValues as IDataObject[];
if (customAttributesValues) {
const customAttributes = {};
for (let i = 0; i < customAttributesValues.length; i++) {
// @ts-ignore
customAttributes[customAttributesValues[i].name] = customAttributesValues[i].value;
}
body.custom_attributes = customAttributes;
}
} else {
const customAttributesJson = validateJSON(this.getNodeParameter('customAttributesJson', i) as string);
if (customAttributesJson) {
body.custom_attributes = customAttributesJson;
}
}
2019-11-21 09:39:04 -08:00
if (operation === 'update') {
const updateBy = this.getNodeParameter('updateBy', 0) as string;
const value = this.getNodeParameter('value', i) as string;
if (updateBy === 'userId') {
body.user_id = value;
2019-11-21 09:39:04 -08:00
}
if (updateBy === 'id') {
body.id = value;
2019-11-21 09:39:04 -08:00
}
if (updateBy === 'email') {
body.email = value;
2019-11-21 09:39:04 -08:00
}
}
2019-11-21 09:39:04 -08:00
try {
responseData = await intercomApiRequest.call(this, '/users', 'POST', body, qs);
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeApiError(this.getNode(), error);
2019-11-21 09:39:04 -08:00
}
}
if (operation === 'get') {
const selectBy = this.getNodeParameter('selectBy', 0) as string;
2019-11-21 09:39:04 -08:00
const value = this.getNodeParameter('value', i) as string;
if (selectBy === 'userId') {
qs.user_id = value;
2019-11-21 09:39:04 -08:00
}
try {
if (selectBy === 'id') {
responseData = await intercomApiRequest.call(this, `/users/${value}`, 'GET', {}, qs);
} else {
responseData = await intercomApiRequest.call(this, '/users', 'GET', {}, qs);
}
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeApiError(this.getNode(), error);
2019-11-21 09:39:04 -08:00
}
}
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const filters = this.getNodeParameter('filters', i) as IDataObject;
Object.assign(qs, filters);
2019-11-21 09:39:04 -08:00
try {
if (returnAll === true) {
responseData = await intercomApiRequestAllItems.call(this, 'users', '/users', 'GET', {}, qs);
} else {
qs.per_page = this.getNodeParameter('limit', i) as number;
responseData = await intercomApiRequest.call(this, '/users', 'GET', {}, qs);
responseData = responseData.users;
}
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeApiError(this.getNode(), error);
2019-11-21 09:39:04 -08:00
}
}
if (operation === 'delete') {
const id = this.getNodeParameter('id', i) as string;
try {
responseData = await intercomApiRequest.call(this, `/users/${id}`, 'DELETE');
} catch (error) {
throw new NodeOperationError(this.getNode(), `Intercom Error: ${JSON.stringify(error)}`);
}
2019-11-21 09:39:04 -08:00
}
}
//https://developers.intercom.com/intercom-api-reference/reference#companies
if (resource === 'company') {
if (operation === 'create' || operation === 'update') {
const id = this.getNodeParameter('companyId', i) as string;
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
2019-11-21 09:39:04 -08:00
const jsonActive = this.getNodeParameter('jsonParameters', i) as boolean;
const body: ICompany = {
company_id: id,
};
if (additionalFields.monthlySpend) {
body.monthly_spend = additionalFields.monthlySpend as number;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.name) {
body.name = additionalFields.name as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.plan) {
body.plan = additionalFields.plan as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.size) {
body.size = additionalFields.size as number;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.website) {
body.website = additionalFields.website as string;
2019-11-21 09:39:04 -08:00
}
if (additionalFields.industry) {
body.industry = additionalFields.industry as string;
2019-11-21 09:39:04 -08:00
}
if (!jsonActive) {
const customAttributesValues = (this.getNodeParameter('customAttributesUi', i) as IDataObject).customAttributesValues as IDataObject[];
if (customAttributesValues) {
const customAttributes = {};
for (let i = 0; i < customAttributesValues.length; i++) {
// @ts-ignore
customAttributes[customAttributesValues[i].name] = customAttributesValues[i].value;
}
body.custom_attributes = customAttributes;
}
} else {
const customAttributesJson = validateJSON(this.getNodeParameter('customAttributesJson', i) as string);
if (customAttributesJson) {
body.custom_attributes = customAttributesJson;
}
}
try {
responseData = await intercomApiRequest.call(this, '/companies', 'POST', body, qs);
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeOperationError(this.getNode(), `Intercom Error: ${JSON.stringify(error)}`);
2019-11-21 09:39:04 -08:00
}
}
if (operation === 'get') {
const selectBy = this.getNodeParameter('selectBy', 0) as string;
2019-11-21 09:39:04 -08:00
const value = this.getNodeParameter('value', i) as string;
if (selectBy === 'companyId') {
qs.company_id = value;
2019-11-21 09:39:04 -08:00
}
if (selectBy === 'name') {
qs.name = value;
2019-11-21 09:39:04 -08:00
}
try {
if (selectBy === 'id') {
responseData = await intercomApiRequest.call(this, `/companies/${value}`, 'GET', {}, qs);
} else {
responseData = await intercomApiRequest.call(this, '/companies', 'GET', {}, qs);
}
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeOperationError(this.getNode(), `Intercom Error: ${JSON.stringify(error)}`);
2019-11-21 09:39:04 -08:00
}
}
if (operation === 'getAll') {
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
const filters = this.getNodeParameter('filters', i) as IDataObject;
Object.assign(qs, filters);
2019-11-21 09:39:04 -08:00
try {
if (returnAll === true) {
responseData = await intercomApiRequestAllItems.call(this, 'companies', '/companies', 'GET', {}, qs);
} else {
qs.per_page = this.getNodeParameter('limit', i) as number;
responseData = await intercomApiRequest.call(this, '/companies', 'GET', {}, qs);
responseData = responseData.companies;
}
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeOperationError(this.getNode(), `Intercom Error: ${JSON.stringify(error)}`);
2019-11-21 09:39:04 -08:00
}
}
2019-11-21 09:52:57 -08:00
if (operation === 'users') {
const listBy = this.getNodeParameter('listBy', 0) as string;
2019-11-21 09:39:04 -08:00
const value = this.getNodeParameter('value', i) as string;
2021-04-24 08:42:31 -07:00
const returnAll = this.getNodeParameter('returnAll', i) as boolean;
if (listBy === 'companyId') {
qs.company_id = value;
2019-11-21 09:39:04 -08:00
}
2021-04-24 08:42:31 -07:00
2019-11-21 09:39:04 -08:00
try {
if (listBy === 'id') {
2021-04-24 08:42:31 -07:00
if (returnAll === true) {
responseData = await intercomApiRequestAllItems.call(this, 'users', `/companies/${value}/users`, 'GET', {}, qs);
} else {
qs.per_page = this.getNodeParameter('limit', i) as number;
responseData = await intercomApiRequest.call(this, `/companies/${value}/users`, 'GET', {}, qs);
responseData = responseData.users;
}
2019-11-21 09:39:04 -08:00
} else {
qs.type = 'users';
2021-04-24 08:42:31 -07:00
if (returnAll === true) {
responseData = await intercomApiRequestAllItems.call(this, 'users', '/companies', 'GET', {}, qs);
} else {
qs.per_page = this.getNodeParameter('limit', i) as number;
responseData = await intercomApiRequest.call(this, '/companies', 'GET', {}, qs);
responseData = responseData.users;
}
2019-11-21 09:39:04 -08:00
}
:sparkles: Improve node error handling (#1309) * Add path mapping and response error interfaces * Add error handling and throwing functionality * Refactor error handling into a single function * Re-implement error handling in Hacker News node * Fix linting details * Re-implement error handling in Spotify node * Re-implement error handling in G Suite Admin node * :construction: create basic setup NodeError * :construction: add httpCodes * :construction: add path priolist * :construction: handle statusCode in error, adjust interfaces * :construction: fixing type issues w/Ivan * :construction: add error exploration * 👔 fix linter issues * :wrench: improve object check * :construction: remove path passing from NodeApiError * :construction: add multi error + refactor findProperty method * 👔 allow any * :wrench: handle multi error message callback * :zap: change return type of callback * :zap: add customCallback to MultiError * :construction: refactor to use INode * :hammer: handle arrays, continue search after first null property found * 🚫 refactor method access * :construction: setup NodeErrorView * :zap: change timestamp to Date.now * :books: Add documentation for methods and constants * :construction: change message setting * 🚚 move NodeErrors to workflow * :sparkles: add new ErrorView for Nodes * :art: improve error notification * :art: refactor interfaces * :zap: add WorkflowOperationError, refactor error throwing * 👕 fix linter issues * :art: rename param * :bug: fix handling normal errors * :zap: add usage of NodeApiError * :art: fix throw new error instead of constructor * :art: remove unnecessary code/comments * :art: adjusted spacing + updated status messages * :art: fix tab indentation * ✨ Replace current errors with custom errors (#1576) * :zap: Introduce NodeApiError in catch blocks * :zap: Introduce NodeOperationError in nodes * :zap: Add missing errors and remove incompatible * :zap: Fix NodeOperationError in incompatible nodes * :wrench: Adjust error handling in missed nodes PayPal, FileMaker, Reddit, Taiga and Facebook Graph API nodes * :hammer: Adjust Strava Trigger node error handling * :hammer: Adjust AWS nodes error handling * :hammer: Remove duplicate instantiation of NodeApiError * :bug: fix strava trigger node error handling * Add XML parsing to NodeApiError constructor (#1633) * :bug: Remove type annotation from catch variable * :sparkles: Add XML parsing to NodeApiError * :zap: Simplify error handling in Rekognition node * :zap: Pass in XML flag in generic functions * :fire: Remove try/catch wrappers at call sites * :hammer: Refactor setting description from XML * :hammer: Refactor let to const in resource loaders * :zap: Find property in parsed XML * :zap: Change let to const * :fire: Remove unneeded try/catch block * :shirt: Fix linting issues * :bug: Fix errors from merge conflict resolution * :zap: Add custom errors to latest contributions * :shirt: Fix linting issues * :zap: Refactor MongoDB helpers for custom errors * :bug: Correct custom error type * :zap: Apply feedback to A nodes * :zap: Apply feedback to missed A node * :zap: Apply feedback to B-D nodes * :zap: Apply feedback to E-F nodes * :zap: Apply feedback to G nodes * :zap: Apply feedback to H-L nodes * :zap: Apply feedback to M nodes * :zap: Apply feedback to P nodes * :zap: Apply feedback to R nodes * :zap: Apply feedback to S nodes * :zap: Apply feedback to T nodes * :zap: Apply feedback to V-Z nodes * :zap: Add HTTP code to iterable node error * :hammer: Standardize e as error * :hammer: Standardize err as error * :zap: Fix error handling for non-standard nodes Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <b.hesseldieck@gmail.com> Co-authored-by: Ben Hesseldieck <1849459+BHesseldieck@users.noreply.github.com>
2021-04-16 09:33:36 -07:00
} catch (error) {
throw new NodeOperationError(this.getNode(), `Intercom Error: ${JSON.stringify(error)}`);
2019-11-21 09:39:04 -08:00
}
}
2019-11-18 13:41:00 -08:00
}
if (Array.isArray(responseData)) {
returnData.push.apply(returnData, responseData as IDataObject[]);
} else {
returnData.push(responseData as IDataObject);
2019-11-16 15:47:28 -08:00
}
}
2019-11-18 13:41:00 -08:00
return [this.helpers.returnJsonArray(returnData)];
2019-11-15 12:10:51 -08:00
}
}