diff --git a/packages/nodes-base/nodes/Hubspot/ContactListDescription.ts b/packages/nodes-base/nodes/Hubspot/ContactListDescription.ts
new file mode 100644
index 0000000000..071a0ff1c5
--- /dev/null
+++ b/packages/nodes-base/nodes/Hubspot/ContactListDescription.ts
@@ -0,0 +1,160 @@
+import {
+ INodeProperties,
+} from 'n8n-workflow';
+
+export const contactListOperations = [
+ {
+ displayName: 'Operation',
+ name: 'operation',
+ type: 'options',
+ displayOptions: {
+ show: {
+ resource: [
+ 'contactList',
+ ],
+ },
+ },
+ options: [
+ {
+ name: 'Add',
+ value: 'add',
+ description: 'Add contact to a list',
+ },
+ {
+ name: 'Remove',
+ value: 'remove',
+ description: 'Remove a contact from a list',
+ },
+ ],
+ default: 'add',
+ description: 'The operation to perform.',
+ },
+] as INodeProperties[];
+
+export const contactListFields = [
+
+ /* -------------------------------------------------------------------------- */
+ /* contactList:add */
+ /* -------------------------------------------------------------------------- */
+ {
+ displayName: 'By',
+ name: 'by',
+ type: 'options',
+ options: [
+ {
+ name: 'Contact ID',
+ value: 'id',
+ },
+ {
+ name: 'Email',
+ value: 'email',
+ },
+ ],
+ required: true,
+ displayOptions: {
+ show: {
+ resource: [
+ 'contactList',
+ ],
+ operation: [
+ 'add',
+ ],
+ },
+ },
+ default: 'email',
+ },
+ {
+ displayName: 'Email',
+ name: 'email',
+ type: 'string',
+ required: true,
+ displayOptions: {
+ show: {
+ resource: [
+ 'contactList',
+ ],
+ operation: [
+ 'add',
+ ],
+ by: [
+ 'email',
+ ],
+ },
+ },
+ default: '',
+ },
+ {
+ displayName: 'Contact ID',
+ name: 'id',
+ type: 'string',
+ required: true,
+ displayOptions: {
+ show: {
+ resource: [
+ 'contactList',
+ ],
+ operation: [
+ 'add',
+ ],
+ by: [
+ 'id',
+ ],
+ },
+ },
+ default: '',
+ },
+ {
+ displayName: 'List ID',
+ name: 'listId',
+ type: 'string',
+ required: true,
+ displayOptions: {
+ show: {
+ resource: [
+ 'contactList',
+ ],
+ operation: [
+ 'add',
+ ],
+ },
+ },
+ default: '',
+ },
+ /* -------------------------------------------------------------------------- */
+ /* contactList:remove */
+ /* -------------------------------------------------------------------------- */
+ {
+ displayName: 'Contact ID',
+ name: 'id',
+ type: 'string',
+ required: true,
+ displayOptions: {
+ show: {
+ resource: [
+ 'contactList',
+ ],
+ operation: [
+ 'remove',
+ ],
+ },
+ },
+ default: '',
+ },
+ {
+ displayName: 'List ID',
+ name: 'listId',
+ type: 'string',
+ required: true,
+ displayOptions: {
+ show: {
+ resource: [
+ 'contactList',
+ ],
+ operation: [
+ 'remove',
+ ],
+ },
+ },
+ default: '',
+ },
+] as INodeProperties[];
diff --git a/packages/nodes-base/nodes/Hubspot/DealDescription.ts b/packages/nodes-base/nodes/Hubspot/DealDescription.ts
index 28e2261fed..7bd4597b8a 100644
--- a/packages/nodes-base/nodes/Hubspot/DealDescription.ts
+++ b/packages/nodes-base/nodes/Hubspot/DealDescription.ts
@@ -1,6 +1,6 @@
import {
INodeProperties,
- } from 'n8n-workflow';
+} from 'n8n-workflow';
export const dealOperations = [
{
@@ -45,6 +45,11 @@ export const dealOperations = [
value: 'getRecentlyModified',
description: 'Get recently modified deals',
},
+ {
+ name: 'Search',
+ value: 'search',
+ description: 'Search deals',
+ },
{
name: 'Update',
value: 'update',
@@ -58,9 +63,9 @@ export const dealOperations = [
export const dealFields = [
-/* -------------------------------------------------------------------------- */
-/* deal:create */
-/* -------------------------------------------------------------------------- */
+ /* -------------------------------------------------------------------------- */
+ /* deal:create */
+ /* -------------------------------------------------------------------------- */
{
displayName: 'Deal Stage',
name: 'stage',
@@ -111,7 +116,7 @@ export const dealFields = [
name: 'associatedCompany',
type: 'multiOptions',
typeOptions: {
- loadOptionsMethod:'getCompanies' ,
+ loadOptionsMethod: 'getCompanies',
},
default: [],
},
@@ -120,7 +125,7 @@ export const dealFields = [
name: 'associatedVids',
type: 'multiOptions',
typeOptions: {
- loadOptionsMethod:'getContacts' ,
+ loadOptionsMethod: 'getContacts',
},
default: [],
},
@@ -188,9 +193,10 @@ export const dealFields = [
},
],
},
-/* -------------------------------------------------------------------------- */
-/* deal:update */
-/* -------------------------------------------------------------------------- */
+
+ /* -------------------------------------------------------------------------- */
+ /* deal:update */
+ /* -------------------------------------------------------------------------- */
{
displayName: 'Deal ID',
name: 'dealId',
@@ -307,9 +313,10 @@ export const dealFields = [
},
],
},
-/* -------------------------------------------------------------------------- */
-/* deal:get */
-/* -------------------------------------------------------------------------- */
+
+ /* -------------------------------------------------------------------------- */
+ /* deal:get */
+ /* -------------------------------------------------------------------------- */
{
displayName: 'Deal ID',
name: 'dealId',
@@ -355,9 +362,10 @@ export const dealFields = [
},
],
},
-/* -------------------------------------------------------------------------- */
-/* deal:getAll */
-/* -------------------------------------------------------------------------- */
+
+ /* -------------------------------------------------------------------------- */
+ /* deal:getAll */
+ /* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
@@ -444,9 +452,10 @@ export const dealFields = [
},
],
},
-/* -------------------------------------------------------------------------- */
-/* deal:delete */
-/* -------------------------------------------------------------------------- */
+
+ /* -------------------------------------------------------------------------- */
+ /* deal:delete */
+ /* -------------------------------------------------------------------------- */
{
displayName: 'Deal ID',
name: 'dealId',
@@ -465,9 +474,10 @@ export const dealFields = [
default: '',
description: 'Unique identifier for a particular deal',
},
-/* -------------------------------------------------------------------------- */
-/* deal:getRecentlyCreated deal:getRecentlyModified */
-/* -------------------------------------------------------------------------- */
+
+ /* -------------------------------------------------------------------------- */
+ /* deal:getRecentlyCreated deal:getRecentlyModified */
+ /* -------------------------------------------------------------------------- */
{
displayName: 'Return All',
name: 'returnAll',
@@ -546,4 +556,238 @@ export const dealFields = [
},
],
},
+
+ /*--------------------------------------------------------------------------- */
+ /* deal:search */
+ /* -------------------------------------------------------------------------- */
+ {
+ displayName: 'Return All',
+ name: 'returnAll',
+ type: 'boolean',
+ displayOptions: {
+ show: {
+ resource: [
+ 'deal',
+ ],
+ operation: [
+ 'search',
+ ],
+ },
+ },
+ default: false,
+ description: 'If all results should be returned or only up to a given limit.',
+ },
+ {
+ displayName: 'Limit',
+ name: 'limit',
+ type: 'number',
+ displayOptions: {
+ show: {
+ resource: [
+ 'deal',
+ ],
+ operation: [
+ 'search',
+ ],
+ returnAll: [
+ false,
+ ],
+ },
+ },
+ typeOptions: {
+ minValue: 1,
+ maxValue: 250,
+ },
+ default: 100,
+ description: 'How many results to return.',
+ },
+ {
+ displayName: 'Filter Groups',
+ name: 'filterGroupsUi',
+ type: 'fixedCollection',
+ default: '',
+ placeholder: 'Add Filter Group',
+ typeOptions: {
+ multipleValues: true,
+ },
+ required: false,
+ displayOptions: {
+ show: {
+ resource: [
+ 'deal',
+ ],
+ operation: [
+ 'search',
+ ],
+ },
+ },
+ options: [
+ {
+ name: 'filterGroupsValues',
+ displayName: 'Filter Group',
+ values: [
+ {
+ displayName: 'Filters',
+ name: 'filtersUi',
+ type: 'fixedCollection',
+ default: '',
+ placeholder: 'Add Filter',
+ typeOptions: {
+ multipleValues: true,
+ },
+ required: false,
+ options: [
+ {
+ name: 'filterValues',
+ displayName: 'Filter',
+ values: [
+ {
+ displayName: 'Property Name',
+ name: 'propertyName',
+ type: 'options',
+ typeOptions: {
+ loadOptionsMethod: 'getDealProperties',
+ },
+ default: '',
+ },
+ {
+ displayName: 'Operator',
+ name: 'operator',
+ type: 'options',
+ options: [
+ {
+ name: 'Equal',
+ value: 'EQ',
+ },
+ {
+ name: 'Not Equal',
+ value: 'NEQ',
+ },
+ {
+ name: 'Less Than',
+ value: 'LT',
+ },
+ {
+ name: 'Less Than Or Equal',
+ value: 'LTE',
+ },
+ {
+ name: 'Greater Than',
+ value: 'GT',
+ },
+ {
+ name: 'Greater Than Or Equal',
+ value: 'GTE',
+ },
+ {
+ name: 'Is Known',
+ value: 'HAS_PROPERTY',
+ },
+ {
+ name: 'Is Unknown',
+ value: 'NOT_HAS_PROPERTY',
+ },
+ {
+ name: 'Contains Exactly',
+ value: 'CONSTAIN_TOKEN',
+ },
+ {
+ name: `Doesn't Contain Exactly`,
+ value: 'NOT_CONSTAIN_TOKEN',
+ },
+ ],
+ default: 'EQ',
+ },
+ {
+ displayName: 'Value',
+ name: 'value',
+ displayOptions: {
+ hide: {
+ operator: [
+ 'HAS_PROPERTY',
+ 'NOT_HAS_PROPERTY',
+ ],
+ },
+ },
+ type: 'string',
+ default: '',
+ },
+ ],
+ },
+ ],
+ description: 'Use filters to limit the results to only CRM objects with matching property values. More info here',
+ },
+ ],
+ },
+ ],
+ description: `When multiple filters are provided within a filterGroup, they will be combined using a logical AND operator.
+ When multiple filterGroups are provided, they will be combined using a logical OR operator.
+ The system supports a maximum of three filterGroups with up to three filters each.
+ More info here`,
+ },
+ {
+ displayName: 'Additional Fields',
+ name: 'additionalFields',
+ type: 'collection',
+ placeholder: 'Add Field',
+ default: {},
+ displayOptions: {
+ show: {
+ resource: [
+ 'deal',
+ ],
+ operation: [
+ 'search',
+ ],
+ },
+ },
+ options: [
+ {
+ displayName: 'Direction',
+ name: 'direction',
+ type: 'options',
+ options: [
+ {
+ name: 'ASC',
+ value: 'ASCENDING',
+ },
+ {
+ name: 'DESC',
+ value: 'DESCENDING',
+ },
+ ],
+ default: 'DESCENDING',
+ description: 'Defines the direction in which search results are ordered. Default value is DESC.',
+ },
+ {
+ displayName: 'Fields',
+ name: 'properties',
+ type: 'multiOptions',
+ typeOptions: {
+ loadOptionsMethod: 'getDealProperties',
+ },
+ default: [],
+ description: `Used to include specific deal properties in the results.
+ By default, the results will only include Deal ID and will not include the values for any properties for your companys.
+ Including this parameter will include the data for the specified property in the results.
+ You can include this parameter multiple times to request multiple properties separed by ,.`,
+ },
+ {
+ displayName: 'Query',
+ name: 'query',
+ type: 'string',
+ default: '',
+ description: 'Perform a text search against all property values for an object type',
+ },
+ {
+ displayName: 'Sort By',
+ name: 'sortBy',
+ type: 'options',
+ typeOptions: {
+ loadOptionsMethod: 'getDealProperties',
+ },
+ default: 'createdate',
+ },
+ ],
+ },
] as INodeProperties[];
diff --git a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts
index e04a829d93..fd2e720447 100644
--- a/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts
+++ b/packages/nodes-base/nodes/Hubspot/Hubspot.node.ts
@@ -14,14 +14,19 @@ import {
import {
hubspotApiRequest,
hubspotApiRequestAllItems,
- } from './GenericFunctions';
+} from './GenericFunctions';
- import {
+import {
contactFields,
contactOperations,
} from './ContactDescription';
- import {
+import {
+ contactListFields,
+ contactListOperations,
+} from './ContactListDescription';
+
+import {
companyFields,
companyOperations,
} from './CompanyDescription';
@@ -34,9 +39,9 @@ import {
import {
formFields,
formOperations,
- } from './FormDescription';
+} from './FormDescription';
- import {
+import {
ticketFields,
ticketOperations,
} from './TicketDescription';
@@ -52,7 +57,7 @@ import {
import {
snakeCase,
- } from 'change-case';
+} from 'change-case';
export class Hubspot implements INodeType {
description: INodeTypeDescription = {
@@ -120,6 +125,10 @@ export class Hubspot implements INodeType {
name: 'Contact',
value: 'contact',
},
+ {
+ name: 'Contact List',
+ value: 'contactList',
+ },
{
name: 'Company',
value: 'company',
@@ -143,6 +152,9 @@ export class Hubspot implements INodeType {
// CONTACT
...contactOperations,
...contactFields,
+ // CONTACT LIST
+ ...contactListOperations,
+ ...contactListFields,
// COMPANY
...companyOperations,
...companyFields,
@@ -543,7 +555,7 @@ export class Hubspot implements INodeType {
const endpoint = '/properties/v1/deals/properties/named/dealtype';
const dealTypes = await hubspotApiRequest.call(this, 'GET', endpoint);
for (const dealType of dealTypes.options) {
- const dealTypeName = dealType.label ;
+ const dealTypeName = dealType.label;
const dealTypeId = dealType.value;
returnData.push({
name: dealTypeName,
@@ -552,7 +564,7 @@ export class Hubspot implements INodeType {
}
return returnData;
},
-
+
// Get all the deal properties to display them to user so that he can
// select them easily
async getDealCustomProperties(this: ILoadOptionsFunctions): Promise {
@@ -571,6 +583,22 @@ export class Hubspot implements INodeType {
}
return returnData;
},
+ // Get all the deal properties to display them to user so that he can
+ // select them easily
+ async getDealProperties(this: ILoadOptionsFunctions): Promise {
+ const returnData: INodePropertyOptions[] = [];
+ const endpoint = '/properties/v2/deals/properties';
+ const properties = await hubspotApiRequest.call(this, 'GET', endpoint, {});
+ for (const property of properties) {
+ const propertyName = property.label;
+ const propertyId = property.name;
+ returnData.push({
+ name: propertyName,
+ value: propertyId,
+ });
+ }
+ return returnData;
+ },
/* -------------------------------------------------------------------------- */
/* FORM */
@@ -802,7 +830,7 @@ export class Hubspot implements INodeType {
const endpoint = '/contacts/v1/lists/all/contacts/all';
const contacts = await hubspotApiRequestAllItems.call(this, 'contacts', 'GET', endpoint);
for (const contact of contacts) {
- const contactName = `${contact.properties.firstname.value} ${contact.properties.lastname.value}` ;
+ const contactName = `${contact.properties.firstname.value} ${contact.properties.lastname.value}`;
const contactId = contact.vid;
returnData.push({
name: contactName,
@@ -823,1426 +851,1506 @@ export class Hubspot implements INodeType {
const qs: IDataObject = {};
const resource = this.getNodeParameter('resource', 0) as string;
const operation = this.getNodeParameter('operation', 0) as string;
- for (let i = 0; i < length; i++) {
- //https://developers.hubspot.com/docs/methods/contacts/create_or_update
- if (resource === 'contact') {
- //https://developers.hubspot.com/docs/methods/companies/create_company
- if (operation === 'upsert') {
- const email = this.getNodeParameter('email', i) as string;
- const resolveData = this.getNodeParameter('resolveData', i) as boolean;
- const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
- const body: IDataObject[] = [];
- if (additionalFields.annualRevenue) {
- body.push({
- property: 'annualrevenue',
- value: (additionalFields.annualRevenue as number).toString(),
- });
- }
- if (additionalFields.city) {
- body.push({
- property: 'city',
- value: additionalFields.city,
- });
- }
- if (additionalFields.clickedFacebookAd) {
- body.push({
- property: 'hs_facebook_ad_clicked',
- value: additionalFields.clickedFacebookAd,
- });
- }
- if (additionalFields.closeDate) {
- body.push({
- property: 'closedate',
- value: new Date(additionalFields.closeDate as string).getTime(),
- });
- }
- if (additionalFields.companyName) {
- body.push({
- property: 'company',
- value: additionalFields.companyName,
- });
- }
- if (additionalFields.companySize) {
- body.push({
- property: 'company_size',
- value: additionalFields.companySize,
- });
- }
- if (additionalFields.description) {
- body.push({
- property: 'description',
- value: additionalFields.description,
- });
- }
- if (additionalFields.contactOwner) {
- body.push({
- property: 'hubspot_owner_id',
- value: additionalFields.contactOwner,
- });
- }
- if (additionalFields.country) {
- body.push({
- property: 'country',
- value: additionalFields.country,
- });
- }
- if (additionalFields.dateOfBirth) {
- body.push({
- property: 'date_of_birth',
- value: additionalFields.dateOfBirth,
- });
- }
- if (additionalFields.degree) {
- body.push({
- property: 'degree',
- value: additionalFields.degree,
- });
- }
- if (additionalFields.facebookClickId) {
- body.push({
- property: 'hs_facebook_click_id',
- value: additionalFields.facebookClickId,
- });
- }
- if (additionalFields.faxNumber) {
- body.push({
- property: 'fax',
- value: additionalFields.faxNumber,
- });
- }
- if (additionalFields.fieldOfStudy) {
- body.push({
- property: 'field_of_study',
- value: additionalFields.fieldOfStudy,
- });
- }
- if (additionalFields.firstName) {
- body.push({
- property: 'firstname',
- value: additionalFields.firstName,
- });
- }
- if (additionalFields.gender) {
- body.push({
- property: 'gender',
- value: additionalFields.gender,
- });
- }
- if (additionalFields.googleAdClickId) {
- body.push({
- property: 'hs_google_click_id',
- value: additionalFields.googleAdClickId,
- });
- }
- if (additionalFields.graduationDate) {
- body.push({
- property: 'graduation_date',
- value: additionalFields.graduationDate,
- });
- }
- if (additionalFields.industry) {
- body.push({
- property: 'industry',
- value: additionalFields.industry,
- });
- }
- if (additionalFields.jobFunction) {
- body.push({
- property: 'job_function',
- value: additionalFields.jobFunction,
- });
- }
- if (additionalFields.jobTitle) {
- body.push({
- property: 'jobtitle',
- value: additionalFields.jobTitle,
- });
- }
- if (additionalFields.lastName) {
- body.push({
- property: 'lastname',
- value: additionalFields.lastName,
- });
- }
- if (additionalFields.leadStatus) {
- body.push({
- property: 'hs_lead_status',
- value: additionalFields.leadStatus,
- });
- }
- if (additionalFields.processingContactData) {
- body.push({
- property: 'hs_legal_basis',
- value: additionalFields.processingContactData,
- });
- }
- if (additionalFields.lifeCycleStage) {
- body.push({
- property: 'lifecyclestage',
- value: additionalFields.lifeCycleStage,
- });
- }
- if (additionalFields.maritalStatus) {
- body.push({
- property: 'marital_status',
- value: additionalFields.maritalStatus,
- });
- }
- if (additionalFields.membershipNote) {
- body.push({
- property: 'hs_content_membership_notes',
- value: additionalFields.membershipNote,
- });
- }
- if (additionalFields.message) {
- body.push({
- property: 'message',
- value: additionalFields.message,
- });
- }
- if (additionalFields.mobilePhoneNumber) {
- body.push({
- property: 'mobilephone',
- value: additionalFields.mobilePhoneNumber,
- });
- }
- if (additionalFields.numberOfEmployees) {
- body.push({
- property: 'numemployees',
- value: additionalFields.numberOfEmployees,
- });
- }
- if (additionalFields.originalSource) {
- body.push({
- property: 'hs_analytics_source',
- value: additionalFields.originalSource,
- });
- }
- if (additionalFields.phoneNumber) {
- body.push({
- property: 'phone',
- value: additionalFields.phoneNumber,
- });
- }
- if (additionalFields.postalCode) {
- body.push({
- property: 'zip',
- value: additionalFields.postalCode,
- });
- }
- if (additionalFields.prefferedLanguage) {
- body.push({
- property: 'hs_language',
- value: additionalFields.prefferedLanguage,
- });
- }
- if (additionalFields.relationshipStatus) {
- body.push({
- property: 'relationship_status',
- value: additionalFields.relationshipStatus,
- });
- }
- if (additionalFields.salutation) {
- body.push({
- property: 'salutation',
- value: additionalFields.salutation,
- });
- }
- if (additionalFields.school) {
- body.push({
- property: 'school',
- value: additionalFields.school,
- });
- }
- if (additionalFields.seniority) {
- body.push({
- property: 'seniority',
- value: additionalFields.seniority,
- });
- }
- if (additionalFields.startDate) {
- body.push({
- property: 'start_date',
- value: additionalFields.startDate,
- });
- }
- if (additionalFields.stateRegion) {
- body.push({
- property: 'state',
- value: additionalFields.stateRegion,
- });
- }
- if (additionalFields.status) {
- body.push({
- property: 'hs_content_membership_status',
- value: additionalFields.status,
- });
- }
- if (additionalFields.streetAddress) {
- body.push({
- property: 'address',
- value: additionalFields.streetAddress,
- });
- }
- if (additionalFields.twitterUsername) {
- body.push({
- property: 'twitterhandle',
- value: additionalFields.twitterUsername,
- });
- }
- if (additionalFields.websiteUrl) {
- body.push({
- property: 'website',
- value: additionalFields.websiteUrl,
- });
- }
- if (additionalFields.workEmail) {
- body.push({
- property: 'work_email',
- value: additionalFields.workEmail,
- });
- }
- if (additionalFields.customPropertiesUi) {
- const customProperties = (additionalFields.customPropertiesUi as IDataObject).customPropertiesValues as IDataObject[];
+ //https://legacydocs.hubspot.com/docs/methods/lists/contact-lists-overview
+ if (resource === 'contactList') {
+ //https://legacydocs.hubspot.com/docs/methods/lists/add_contact_to_list
+ if (operation === 'add') {
+ const listId = this.getNodeParameter('listId', 0) as string;
+ const by = this.getNodeParameter('by', 0) as string;
+ const body: { [key: string]: [] } = { emails: [], vids: [] };
+ for (let i = 0; i < length; i++) {
+ if (by === 'id') {
+ const id = this.getNodeParameter('id', i) as string;
+ body.vids.push(parseInt(id, 10) as never);
+ } else {
+ const email = this.getNodeParameter('email', i) as string;
+ body.emails.push(email as never);
+ }
+ }
+ responseData = await hubspotApiRequest.call(this, 'POST', `/contacts/v1/lists/${listId}/add`, body);
+ returnData.push(responseData);
+ }
+ //https://legacydocs.hubspot.com/docs/methods/lists/remove_contact_from_list
+ if (operation === 'remove') {
+ const listId = this.getNodeParameter('listId', 0) as string;
+ const body: { [key: string]: [] } = { vids: [] };
+ for (let i = 0; i < length; i++) {
+ const id = this.getNodeParameter('id', i) as string;
+ body.vids.push(parseInt(id, 10) as never);
+ }
+ responseData = await hubspotApiRequest.call(this, 'POST', `/contacts/v1/lists/${listId}/remove`, body);
+ returnData.push(responseData);
+ }
+ } else {
+ for (let i = 0; i < length; i++) {
+ //https://developers.hubspot.com/docs/methods/contacts/create_or_update
+ if (resource === 'contact') {
+ //https://developers.hubspot.com/docs/methods/companies/create_company
+ if (operation === 'upsert') {
+ const email = this.getNodeParameter('email', i) as string;
+ const resolveData = this.getNodeParameter('resolveData', i) as boolean;
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ const body: IDataObject[] = [];
+ if (additionalFields.annualRevenue) {
+ body.push({
+ property: 'annualrevenue',
+ value: (additionalFields.annualRevenue as number).toString(),
+ });
+ }
+ if (additionalFields.city) {
+ body.push({
+ property: 'city',
+ value: additionalFields.city,
+ });
+ }
+ if (additionalFields.clickedFacebookAd) {
+ body.push({
+ property: 'hs_facebook_ad_clicked',
+ value: additionalFields.clickedFacebookAd,
+ });
+ }
+ if (additionalFields.closeDate) {
+ body.push({
+ property: 'closedate',
+ value: new Date(additionalFields.closeDate as string).getTime(),
+ });
+ }
+ if (additionalFields.companyName) {
+ body.push({
+ property: 'company',
+ value: additionalFields.companyName,
+ });
+ }
+ if (additionalFields.companySize) {
+ body.push({
+ property: 'company_size',
+ value: additionalFields.companySize,
+ });
+ }
+ if (additionalFields.description) {
+ body.push({
+ property: 'description',
+ value: additionalFields.description,
+ });
+ }
+ if (additionalFields.contactOwner) {
+ body.push({
+ property: 'hubspot_owner_id',
+ value: additionalFields.contactOwner,
+ });
+ }
+ if (additionalFields.country) {
+ body.push({
+ property: 'country',
+ value: additionalFields.country,
+ });
+ }
+ if (additionalFields.dateOfBirth) {
+ body.push({
+ property: 'date_of_birth',
+ value: additionalFields.dateOfBirth,
+ });
+ }
+ if (additionalFields.degree) {
+ body.push({
+ property: 'degree',
+ value: additionalFields.degree,
+ });
+ }
+ if (additionalFields.facebookClickId) {
+ body.push({
+ property: 'hs_facebook_click_id',
+ value: additionalFields.facebookClickId,
+ });
+ }
+ if (additionalFields.faxNumber) {
+ body.push({
+ property: 'fax',
+ value: additionalFields.faxNumber,
+ });
+ }
+ if (additionalFields.fieldOfStudy) {
+ body.push({
+ property: 'field_of_study',
+ value: additionalFields.fieldOfStudy,
+ });
+ }
+ if (additionalFields.firstName) {
+ body.push({
+ property: 'firstname',
+ value: additionalFields.firstName,
+ });
+ }
+ if (additionalFields.gender) {
+ body.push({
+ property: 'gender',
+ value: additionalFields.gender,
+ });
+ }
+ if (additionalFields.googleAdClickId) {
+ body.push({
+ property: 'hs_google_click_id',
+ value: additionalFields.googleAdClickId,
+ });
+ }
+ if (additionalFields.graduationDate) {
+ body.push({
+ property: 'graduation_date',
+ value: additionalFields.graduationDate,
+ });
+ }
+ if (additionalFields.industry) {
+ body.push({
+ property: 'industry',
+ value: additionalFields.industry,
+ });
+ }
+ if (additionalFields.jobFunction) {
+ body.push({
+ property: 'job_function',
+ value: additionalFields.jobFunction,
+ });
+ }
+ if (additionalFields.jobTitle) {
+ body.push({
+ property: 'jobtitle',
+ value: additionalFields.jobTitle,
+ });
+ }
+ if (additionalFields.lastName) {
+ body.push({
+ property: 'lastname',
+ value: additionalFields.lastName,
+ });
+ }
+ if (additionalFields.leadStatus) {
+ body.push({
+ property: 'hs_lead_status',
+ value: additionalFields.leadStatus,
+ });
+ }
+ if (additionalFields.processingContactData) {
+ body.push({
+ property: 'hs_legal_basis',
+ value: additionalFields.processingContactData,
+ });
+ }
+ if (additionalFields.lifeCycleStage) {
+ body.push({
+ property: 'lifecyclestage',
+ value: additionalFields.lifeCycleStage,
+ });
+ }
+ if (additionalFields.maritalStatus) {
+ body.push({
+ property: 'marital_status',
+ value: additionalFields.maritalStatus,
+ });
+ }
+ if (additionalFields.membershipNote) {
+ body.push({
+ property: 'hs_content_membership_notes',
+ value: additionalFields.membershipNote,
+ });
+ }
+ if (additionalFields.message) {
+ body.push({
+ property: 'message',
+ value: additionalFields.message,
+ });
+ }
+ if (additionalFields.mobilePhoneNumber) {
+ body.push({
+ property: 'mobilephone',
+ value: additionalFields.mobilePhoneNumber,
+ });
+ }
+ if (additionalFields.numberOfEmployees) {
+ body.push({
+ property: 'numemployees',
+ value: additionalFields.numberOfEmployees,
+ });
+ }
+ if (additionalFields.originalSource) {
+ body.push({
+ property: 'hs_analytics_source',
+ value: additionalFields.originalSource,
+ });
+ }
+ if (additionalFields.phoneNumber) {
+ body.push({
+ property: 'phone',
+ value: additionalFields.phoneNumber,
+ });
+ }
+ if (additionalFields.postalCode) {
+ body.push({
+ property: 'zip',
+ value: additionalFields.postalCode,
+ });
+ }
+ if (additionalFields.prefferedLanguage) {
+ body.push({
+ property: 'hs_language',
+ value: additionalFields.prefferedLanguage,
+ });
+ }
+ if (additionalFields.relationshipStatus) {
+ body.push({
+ property: 'relationship_status',
+ value: additionalFields.relationshipStatus,
+ });
+ }
+ if (additionalFields.salutation) {
+ body.push({
+ property: 'salutation',
+ value: additionalFields.salutation,
+ });
+ }
+ if (additionalFields.school) {
+ body.push({
+ property: 'school',
+ value: additionalFields.school,
+ });
+ }
+ if (additionalFields.seniority) {
+ body.push({
+ property: 'seniority',
+ value: additionalFields.seniority,
+ });
+ }
+ if (additionalFields.startDate) {
+ body.push({
+ property: 'start_date',
+ value: additionalFields.startDate,
+ });
+ }
+ if (additionalFields.stateRegion) {
+ body.push({
+ property: 'state',
+ value: additionalFields.stateRegion,
+ });
+ }
+ if (additionalFields.status) {
+ body.push({
+ property: 'hs_content_membership_status',
+ value: additionalFields.status,
+ });
+ }
+ if (additionalFields.streetAddress) {
+ body.push({
+ property: 'address',
+ value: additionalFields.streetAddress,
+ });
+ }
+ if (additionalFields.twitterUsername) {
+ body.push({
+ property: 'twitterhandle',
+ value: additionalFields.twitterUsername,
+ });
+ }
+ if (additionalFields.websiteUrl) {
+ body.push({
+ property: 'website',
+ value: additionalFields.websiteUrl,
+ });
+ }
+ if (additionalFields.workEmail) {
+ body.push({
+ property: 'work_email',
+ value: additionalFields.workEmail,
+ });
+ }
- if (customProperties) {
- for (const customProperty of customProperties) {
- body.push({
- property: customProperty.property,
- value: customProperty.value,
- });
+ if (additionalFields.customPropertiesUi) {
+ const customProperties = (additionalFields.customPropertiesUi as IDataObject).customPropertiesValues as IDataObject[];
+
+ if (customProperties) {
+ for (const customProperty of customProperties) {
+ body.push({
+ property: customProperty.property,
+ value: customProperty.value,
+ });
+ }
}
}
- }
- const endpoint = `/contacts/v1/contact/createOrUpdate/email/${email}`;
- responseData = await hubspotApiRequest.call(this, 'POST', endpoint, { properties: body });
+ const endpoint = `/contacts/v1/contact/createOrUpdate/email/${email}`;
+ responseData = await hubspotApiRequest.call(this, 'POST', endpoint, { properties: body });
- if (additionalFields.associatedCompanyId) {
- const companyAssociations: IDataObject[] = [];
+ if (additionalFields.associatedCompanyId) {
+ const companyAssociations: IDataObject[] = [];
companyAssociations.push({
fromObjectId: responseData.vid,
toObjectId: additionalFields.associatedCompanyId,
category: 'HUBSPOT_DEFINED',
definitionId: 1,
});
- await hubspotApiRequest.call(this, 'PUT', '/crm-associations/v1/associations/create-batch', companyAssociations);
- }
+ await hubspotApiRequest.call(this, 'PUT', '/crm-associations/v1/associations/create-batch', companyAssociations);
+ }
- if (resolveData) {
- const isNew = responseData.isNew;
- const qs: IDataObject = {};
+ if (resolveData) {
+ const isNew = responseData.isNew;
+ const qs: IDataObject = {};
+ if (additionalFields.properties) {
+ qs.property = additionalFields.properties as string[];
+ }
+ responseData = await hubspotApiRequest.call(this, 'GET', `/contacts/v1/contact/vid/${responseData.vid}/profile`, {}, qs);
+ responseData.isNew = isNew;
+ }
+ }
+ //https://developers.hubspot.com/docs/methods/contacts/get_contact
+ if (operation === 'get') {
+ const contactId = this.getNodeParameter('contactId', i) as string;
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ if (additionalFields.formSubmissionMode) {
+ qs.formSubmissionMode = additionalFields.formSubmissionMode as string;
+ }
+ if (additionalFields.listMerberships) {
+ qs.showListMemberships = additionalFields.listMerberships as boolean;
+ }
if (additionalFields.properties) {
qs.property = additionalFields.properties as string[];
}
- responseData = await hubspotApiRequest.call(this, 'GET', `/contacts/v1/contact/vid/${responseData.vid}/profile`, {}, qs);
- responseData.isNew = isNew;
- }
- }
- //https://developers.hubspot.com/docs/methods/contacts/get_contact
- if (operation === 'get') {
- const contactId = this.getNodeParameter('contactId', i) as string;
- const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
- if (additionalFields.formSubmissionMode) {
- qs.formSubmissionMode = additionalFields.formSubmissionMode as string;
- }
- if (additionalFields.listMerberships) {
- qs.showListMemberships = additionalFields.listMerberships as boolean;
- }
- if (additionalFields.properties) {
- qs.property = additionalFields.properties as string[];
- }
- if (additionalFields.propertyMode) {
- qs.propertyMode = snakeCase(additionalFields.propertyMode as string);
- }
- const endpoint = `/contacts/v1/contact/vid/${contactId}/profile`;
- responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
- }
- //https://developers.hubspot.com/docs/methods/contacts/get_contacts
- if (operation === 'getAll') {
- const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
- const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
- if (additionalFields.formSubmissionMode) {
- qs.formSubmissionMode = additionalFields.formSubmissionMode as string;
- }
- if (additionalFields.listMerberships) {
- qs.showListMemberships = additionalFields.listMerberships as boolean;
- }
- if (additionalFields.properties) {
- qs.property = additionalFields.properties as string[];
- }
- if (additionalFields.propertyMode) {
- qs.propertyMode = snakeCase(additionalFields.propertyMode as string);
- }
- const endpoint = '/contacts/v1/lists/all/contacts/all';
- if (returnAll) {
- responseData = await hubspotApiRequestAllItems.call(this, 'contacts', 'GET', endpoint, {}, qs);
- } else {
- qs.count = this.getNodeParameter('limit', 0) as number;
+ if (additionalFields.propertyMode) {
+ qs.propertyMode = snakeCase(additionalFields.propertyMode as string);
+ }
+ const endpoint = `/contacts/v1/contact/vid/${contactId}/profile`;
responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
- responseData = responseData.contacts;
}
- }
- //https://developers.hubspot.com/docs/methods/contacts/get_recently_created_contacts
- if (operation === 'getRecentlyCreatedUpdated') {
- let endpoint;
- const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
- const filters = this.getNodeParameter('filters', i) as IDataObject;
- if (filters.formSubmissionMode) {
- qs.formSubmissionMode = filters.formSubmissionMode as string;
- }
- if (filters.listMerberships) {
- qs.showListMemberships = filters.listMerberships as boolean;
- }
- if (filters.properties) {
- qs.property = filters.properties as string[];
- }
- if (filters.propertyMode) {
- qs.propertyMode = snakeCase(filters.propertyMode as string);
+ //https://developers.hubspot.com/docs/methods/contacts/get_contacts
+ if (operation === 'getAll') {
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
+ if (additionalFields.formSubmissionMode) {
+ qs.formSubmissionMode = additionalFields.formSubmissionMode as string;
+ }
+ if (additionalFields.listMerberships) {
+ qs.showListMemberships = additionalFields.listMerberships as boolean;
+ }
+ if (additionalFields.properties) {
+ qs.property = additionalFields.properties as string[];
+ }
+ if (additionalFields.propertyMode) {
+ qs.propertyMode = snakeCase(additionalFields.propertyMode as string);
+ }
+ const endpoint = '/contacts/v1/lists/all/contacts/all';
+ if (returnAll) {
+ responseData = await hubspotApiRequestAllItems.call(this, 'contacts', 'GET', endpoint, {}, qs);
+ } else {
+ qs.count = this.getNodeParameter('limit', 0) as number;
+ responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
+ responseData = responseData.contacts;
+ }
}
+ //https://developers.hubspot.com/docs/methods/contacts/get_recently_created_contacts
+ if (operation === 'getRecentlyCreatedUpdated') {
+ let endpoint;
+ const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
+ const filters = this.getNodeParameter('filters', i) as IDataObject;
+ if (filters.formSubmissionMode) {
+ qs.formSubmissionMode = filters.formSubmissionMode as string;
+ }
+ if (filters.listMerberships) {
+ qs.showListMemberships = filters.listMerberships as boolean;
+ }
+ if (filters.properties) {
+ qs.property = filters.properties as string[];
+ }
+ if (filters.propertyMode) {
+ qs.propertyMode = snakeCase(filters.propertyMode as string);
+ }
- endpoint = '/contacts/v1/lists/recently_updated/contacts/recent';
+ endpoint = '/contacts/v1/lists/recently_updated/contacts/recent';
- if (returnAll) {
- responseData = await hubspotApiRequestAllItems.call(this, 'contacts', 'GET', endpoint, {}, qs);
- } else {
- qs.count = this.getNodeParameter('limit', 0) as number;
- responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
- responseData = responseData.contacts;
+ if (returnAll) {
+ responseData = await hubspotApiRequestAllItems.call(this, 'contacts', 'GET', endpoint, {}, qs);
+ } else {
+ qs.count = this.getNodeParameter('limit', 0) as number;
+ responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
+ responseData = responseData.contacts;
+ }
}
- }
- //https://developers.hubspot.com/docs/methods/contacts/delete_contact
- if (operation === 'delete') {
- const contactId = this.getNodeParameter('contactId', i) as string;
- const endpoint = `/contacts/v1/contact/vid/${contactId}`;
- responseData = await hubspotApiRequest.call(this, 'DELETE', endpoint);
- }
- //https://developers.hubspot.com/docs/api/crm/search
- if (operation === 'search') {
- const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
- const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
- const filtersGroupsUi = this.getNodeParameter('filterGroupsUi', i) as IDataObject;
- const sortBy = additionalFields.sortBy || 'createdate';
- const direction = additionalFields.direction || 'DESCENDING';
+ //https://developers.hubspot.com/docs/methods/contacts/delete_contact
+ if (operation === 'delete') {
+ const contactId = this.getNodeParameter('contactId', i) as string;
+ const endpoint = `/contacts/v1/contact/vid/${contactId}`;
+ responseData = await hubspotApiRequest.call(this, 'DELETE', endpoint);
+ }
+ //https://developers.hubspot.com/docs/api/crm/search
+ if (operation === 'search') {
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
+ const filtersGroupsUi = this.getNodeParameter('filterGroupsUi', i) as IDataObject;
+ const sortBy = additionalFields.sortBy || 'createdate';
+ const direction = additionalFields.direction || 'DESCENDING';
- const body: IDataObject = {
- sorts: [
- {
- propertyName: sortBy,
- direction,
- },
- ],
- };
+ const body: IDataObject = {
+ sorts: [
+ {
+ propertyName: sortBy,
+ direction,
+ },
+ ],
+ };
- if (filtersGroupsUi) {
- const filterGroupValues = (filtersGroupsUi as IDataObject).filterGroupsValues as IDataObject[];
- if (filterGroupValues) {
- body.filterGroups = [];
- for (const filterGroupValue of filterGroupValues) {
- if (filterGroupValue.filtersUi) {
- const filterValues = (filterGroupValue.filtersUi as IDataObject).filterValues as IDataObject[];
- if (filterValues) {
- //@ts-ignore
- body.filterGroups.push({ filters: filterValues });
+ if (filtersGroupsUi) {
+ const filterGroupValues = (filtersGroupsUi as IDataObject).filterGroupsValues as IDataObject[];
+ if (filterGroupValues) {
+ body.filterGroups = [];
+ for (const filterGroupValue of filterGroupValues) {
+ if (filterGroupValue.filtersUi) {
+ const filterValues = (filterGroupValue.filtersUi as IDataObject).filterValues as IDataObject[];
+ if (filterValues) {
+ //@ts-ignore
+ body.filterGroups.push({ filters: filterValues });
+ }
}
}
}
}
- }
- Object.assign(body, additionalFields);
+ Object.assign(body, additionalFields);
- const endpoint = '/crm/v3/objects/contacts/search';
+ const endpoint = '/crm/v3/objects/contacts/search';
- if (returnAll) {
+ if (returnAll) {
- responseData = await hubspotApiRequestAllItems.call(this, 'results', 'POST', endpoint, body, qs);
+ responseData = await hubspotApiRequestAllItems.call(this, 'results', 'POST', endpoint, body, qs);
- } else {
- qs.count = this.getNodeParameter('limit', 0) as number;
- responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body, qs);
- responseData = responseData.results;
+ } else {
+ qs.count = this.getNodeParameter('limit', 0) as number;
+ responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body, qs);
+ responseData = responseData.results;
+ }
}
}
- }
- //https://developers.hubspot.com/docs/methods/companies/companies-overview
- if (resource === 'company') {
- //https://developers.hubspot.com/docs/methods/companies/create_company
- if (operation === 'create') {
- const name = this.getNodeParameter('name', i) as string;
- const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
- const body: IDataObject[] = [];
- body.push({
- name: 'name',
- value: name,
- });
- if (additionalFields.aboutUs) {
- body.push({
- name: 'about_us',
- value: additionalFields.aboutUs,
- });
- }
- if (additionalFields.annualRevenue) {
- body.push({
- name: 'annualrevenue',
- value: (additionalFields.annualRevenue as number).toString(),
- });
- }
- if (additionalFields.city) {
- body.push({
- name: 'city',
- value: additionalFields.city,
- });
- }
- if (additionalFields.closeDate) {
- body.push({
- name: 'closedate',
- value: new Date(additionalFields.closeDate as string).getTime(),
- });
- }
- if (additionalFields.companyDomainName) {
- body.push({
- name: 'domain',
- value: additionalFields.companyDomainName,
- });
- }
- if (additionalFields.companyOwner) {
- body.push({
- name: 'hubspot_owner_id',
- value: additionalFields.companyOwner,
- });
- }
- if (additionalFields.countryRegion) {
- body.push({
- name: 'country',
- value: additionalFields.countryRegion,
- });
- }
- if (additionalFields.description) {
- body.push({
- name: 'description',
- value: additionalFields.description,
- });
- }
- if (additionalFields.facebookFans) {
- body.push({
- name: 'facebookfans',
- value: additionalFields.facebookFans,
- });
- }
- if (additionalFields.googlePlusPage) {
- body.push({
- name: 'googleplus_page',
- value: additionalFields.googlePlusPage,
- });
- }
- if (additionalFields.industry) {
- body.push({
- name: 'industry',
- value: additionalFields.industry,
- });
- }
- if (additionalFields.isPublic) {
- body.push({
- name: 'is_public',
- value: additionalFields.isPublic,
- });
- }
- if (additionalFields.leadStatus) {
- body.push({
- name: 'hs_lead_status',
- value: additionalFields.leadStatus,
- });
- }
- if (additionalFields.lifecycleStatus) {
- body.push({
- name: 'lifecyclestage',
- value: additionalFields.lifecycleStatus,
- });
- }
- if (additionalFields.linkedinBio) {
- body.push({
- name: 'linkedinbio',
- value: additionalFields.linkedinBio,
- });
- }
- if (additionalFields.linkedInCompanyPage) {
- body.push({
- name: 'linkedin_company_page',
- value: additionalFields.linkedInCompanyPage,
- });
- }
- if (additionalFields.numberOfEmployees) {
- body.push({
- name: 'numberofemployees',
- value: additionalFields.numberOfEmployees,
- });
- }
- if (additionalFields.originalSourceType) {
- body.push({
- name: 'hs_analytics_source',
- value: additionalFields.originalSourceType,
- });
- }
- if (additionalFields.phoneNumber) {
- body.push({
- name: 'phone',
- value: additionalFields.phoneNumber,
- });
- }
- if (additionalFields.postalCode) {
- body.push({
- name: 'zip',
- value: additionalFields.postalCode,
- });
- }
- if (additionalFields.stateRegion) {
- body.push({
- name: 'state',
- value: additionalFields.stateRegion,
- });
- }
- if (additionalFields.streetAddress) {
- body.push({
- name: 'address',
- value: additionalFields.streetAddress,
- });
- }
- if (additionalFields.streetAddress2) {
- body.push({
- name: 'address2',
- value: additionalFields.streetAddress2,
- });
- }
- if (additionalFields.targetAccount) {
- body.push({
- name: 'hs_target_account',
- value: additionalFields.targetAccount,
- });
- }
- if (additionalFields.timezone) {
- body.push({
- name: 'timezone',
- value: additionalFields.timezone,
- });
- }
- if (additionalFields.totalMoneyRaised) {
- body.push({
- name: 'total_money_raised',
- value: additionalFields.totalMoneyRaised,
- });
- }
- if (additionalFields.twitterBio) {
- body.push({
- name: 'twitterbio',
- value: additionalFields.twitterBio,
- });
- }
- if (additionalFields.twitterFollowers) {
- body.push({
- name: 'twitterfollowers',
- value: additionalFields.twitterFollowers,
- });
- }
- if (additionalFields.twitterHandle) {
- body.push({
- name: 'twitterhandle',
- value: additionalFields.twitterHandle,
- });
- }
- if (additionalFields.type) {
- body.push({
- name: 'type',
- value: additionalFields.type,
- });
- }
- if (additionalFields.websiteUrl) {
- body.push({
- name: 'website',
- value: additionalFields.websiteUrl,
- });
- }
- if (additionalFields.webTechnologies) {
- body.push({
- name: 'web_technologies',
- value: additionalFields.webTechnologies,
- });
- }
- if (additionalFields.yearFounded) {
- body.push({
- name: 'founded_year',
- value: additionalFields.yearFounded,
- });
- }
- const endpoint = '/companies/v2/companies';
- responseData = await hubspotApiRequest.call(this, 'POST', endpoint, { properties: body });
- }
- //https://developers.hubspot.com/docs/methods/companies/update_company
- if (operation === 'update') {
- const companyId = this.getNodeParameter('companyId', i) as string;
- const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
- const body: IDataObject[] = [];
- if (updateFields.name) {
+ //https://developers.hubspot.com/docs/methods/companies/companies-overview
+ if (resource === 'company') {
+ //https://developers.hubspot.com/docs/methods/companies/create_company
+ if (operation === 'create') {
+ const name = this.getNodeParameter('name', i) as string;
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ const body: IDataObject[] = [];
body.push({
name: 'name',
- value: updateFields.name,
+ value: name,
});
+ if (additionalFields.aboutUs) {
+ body.push({
+ name: 'about_us',
+ value: additionalFields.aboutUs,
+ });
+ }
+ if (additionalFields.annualRevenue) {
+ body.push({
+ name: 'annualrevenue',
+ value: (additionalFields.annualRevenue as number).toString(),
+ });
+ }
+ if (additionalFields.city) {
+ body.push({
+ name: 'city',
+ value: additionalFields.city,
+ });
+ }
+ if (additionalFields.closeDate) {
+ body.push({
+ name: 'closedate',
+ value: new Date(additionalFields.closeDate as string).getTime(),
+ });
+ }
+ if (additionalFields.companyDomainName) {
+ body.push({
+ name: 'domain',
+ value: additionalFields.companyDomainName,
+ });
+ }
+ if (additionalFields.companyOwner) {
+ body.push({
+ name: 'hubspot_owner_id',
+ value: additionalFields.companyOwner,
+ });
+ }
+ if (additionalFields.countryRegion) {
+ body.push({
+ name: 'country',
+ value: additionalFields.countryRegion,
+ });
+ }
+ if (additionalFields.description) {
+ body.push({
+ name: 'description',
+ value: additionalFields.description,
+ });
+ }
+ if (additionalFields.facebookFans) {
+ body.push({
+ name: 'facebookfans',
+ value: additionalFields.facebookFans,
+ });
+ }
+ if (additionalFields.googlePlusPage) {
+ body.push({
+ name: 'googleplus_page',
+ value: additionalFields.googlePlusPage,
+ });
+ }
+ if (additionalFields.industry) {
+ body.push({
+ name: 'industry',
+ value: additionalFields.industry,
+ });
+ }
+ if (additionalFields.isPublic) {
+ body.push({
+ name: 'is_public',
+ value: additionalFields.isPublic,
+ });
+ }
+ if (additionalFields.leadStatus) {
+ body.push({
+ name: 'hs_lead_status',
+ value: additionalFields.leadStatus,
+ });
+ }
+ if (additionalFields.lifecycleStatus) {
+ body.push({
+ name: 'lifecyclestage',
+ value: additionalFields.lifecycleStatus,
+ });
+ }
+ if (additionalFields.linkedinBio) {
+ body.push({
+ name: 'linkedinbio',
+ value: additionalFields.linkedinBio,
+ });
+ }
+ if (additionalFields.linkedInCompanyPage) {
+ body.push({
+ name: 'linkedin_company_page',
+ value: additionalFields.linkedInCompanyPage,
+ });
+ }
+ if (additionalFields.numberOfEmployees) {
+ body.push({
+ name: 'numberofemployees',
+ value: additionalFields.numberOfEmployees,
+ });
+ }
+ if (additionalFields.originalSourceType) {
+ body.push({
+ name: 'hs_analytics_source',
+ value: additionalFields.originalSourceType,
+ });
+ }
+ if (additionalFields.phoneNumber) {
+ body.push({
+ name: 'phone',
+ value: additionalFields.phoneNumber,
+ });
+ }
+ if (additionalFields.postalCode) {
+ body.push({
+ name: 'zip',
+ value: additionalFields.postalCode,
+ });
+ }
+ if (additionalFields.stateRegion) {
+ body.push({
+ name: 'state',
+ value: additionalFields.stateRegion,
+ });
+ }
+ if (additionalFields.streetAddress) {
+ body.push({
+ name: 'address',
+ value: additionalFields.streetAddress,
+ });
+ }
+ if (additionalFields.streetAddress2) {
+ body.push({
+ name: 'address2',
+ value: additionalFields.streetAddress2,
+ });
+ }
+ if (additionalFields.targetAccount) {
+ body.push({
+ name: 'hs_target_account',
+ value: additionalFields.targetAccount,
+ });
+ }
+ if (additionalFields.timezone) {
+ body.push({
+ name: 'timezone',
+ value: additionalFields.timezone,
+ });
+ }
+ if (additionalFields.totalMoneyRaised) {
+ body.push({
+ name: 'total_money_raised',
+ value: additionalFields.totalMoneyRaised,
+ });
+ }
+ if (additionalFields.twitterBio) {
+ body.push({
+ name: 'twitterbio',
+ value: additionalFields.twitterBio,
+ });
+ }
+ if (additionalFields.twitterFollowers) {
+ body.push({
+ name: 'twitterfollowers',
+ value: additionalFields.twitterFollowers,
+ });
+ }
+ if (additionalFields.twitterHandle) {
+ body.push({
+ name: 'twitterhandle',
+ value: additionalFields.twitterHandle,
+ });
+ }
+ if (additionalFields.type) {
+ body.push({
+ name: 'type',
+ value: additionalFields.type,
+ });
+ }
+ if (additionalFields.websiteUrl) {
+ body.push({
+ name: 'website',
+ value: additionalFields.websiteUrl,
+ });
+ }
+ if (additionalFields.webTechnologies) {
+ body.push({
+ name: 'web_technologies',
+ value: additionalFields.webTechnologies,
+ });
+ }
+ if (additionalFields.yearFounded) {
+ body.push({
+ name: 'founded_year',
+ value: additionalFields.yearFounded,
+ });
+ }
+ const endpoint = '/companies/v2/companies';
+ responseData = await hubspotApiRequest.call(this, 'POST', endpoint, { properties: body });
}
- if (updateFields.aboutUs) {
- body.push({
- name: 'about_us',
- value: updateFields.aboutUs,
- });
+ //https://developers.hubspot.com/docs/methods/companies/update_company
+ if (operation === 'update') {
+ const companyId = this.getNodeParameter('companyId', i) as string;
+ const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
+ const body: IDataObject[] = [];
+ if (updateFields.name) {
+ body.push({
+ name: 'name',
+ value: updateFields.name,
+ });
+ }
+ if (updateFields.aboutUs) {
+ body.push({
+ name: 'about_us',
+ value: updateFields.aboutUs,
+ });
+ }
+ if (updateFields.annualRevenue) {
+ body.push({
+ name: 'annualrevenue',
+ value: (updateFields.annualRevenue as number).toString(),
+ });
+ }
+ if (updateFields.city) {
+ body.push({
+ name: 'city',
+ value: updateFields.city,
+ });
+ }
+ if (updateFields.closeDate) {
+ body.push({
+ name: 'closedate',
+ value: new Date(updateFields.closeDate as string).getTime(),
+ });
+ }
+ if (updateFields.companyDomainName) {
+ body.push({
+ name: 'domain',
+ value: updateFields.companyDomainName,
+ });
+ }
+ if (updateFields.companyOwner) {
+ body.push({
+ name: 'hubspot_owner_id',
+ value: updateFields.companyOwner,
+ });
+ }
+ if (updateFields.countryRegion) {
+ body.push({
+ name: 'country',
+ value: updateFields.countryRegion,
+ });
+ }
+ if (updateFields.description) {
+ body.push({
+ name: 'description',
+ value: updateFields.description,
+ });
+ }
+ if (updateFields.facebookFans) {
+ body.push({
+ name: 'facebookfans',
+ value: updateFields.facebookFans,
+ });
+ }
+ if (updateFields.googlePlusPage) {
+ body.push({
+ name: 'googleplus_page',
+ value: updateFields.googlePlusPage,
+ });
+ }
+ if (updateFields.industry) {
+ body.push({
+ name: 'industry',
+ value: updateFields.industry,
+ });
+ }
+ if (updateFields.isPublic) {
+ body.push({
+ name: 'is_public',
+ value: updateFields.isPublic,
+ });
+ }
+ if (updateFields.leadStatus) {
+ body.push({
+ name: 'hs_lead_status',
+ value: updateFields.leadStatus,
+ });
+ }
+ if (updateFields.lifecycleStatus) {
+ body.push({
+ name: 'lifecyclestage',
+ value: updateFields.lifecycleStatus,
+ });
+ }
+ if (updateFields.linkedinBio) {
+ body.push({
+ name: 'linkedinbio',
+ value: updateFields.linkedinBio,
+ });
+ }
+ if (updateFields.linkedInCompanyPage) {
+ body.push({
+ name: 'linkedin_company_page',
+ value: updateFields.linkedInCompanyPage,
+ });
+ }
+ if (updateFields.numberOfEmployees) {
+ body.push({
+ name: 'numberofemployees',
+ value: updateFields.numberOfEmployees,
+ });
+ }
+ if (updateFields.originalSourceType) {
+ body.push({
+ name: 'hs_analytics_source',
+ value: updateFields.originalSourceType,
+ });
+ }
+ if (updateFields.phoneNumber) {
+ body.push({
+ name: 'phone',
+ value: updateFields.phoneNumber,
+ });
+ }
+ if (updateFields.postalCode) {
+ body.push({
+ name: 'zip',
+ value: updateFields.postalCode,
+ });
+ }
+ if (updateFields.stateRegion) {
+ body.push({
+ name: 'state',
+ value: updateFields.stateRegion,
+ });
+ }
+ if (updateFields.streetAddress) {
+ body.push({
+ name: 'address',
+ value: updateFields.streetAddress,
+ });
+ }
+ if (updateFields.streetAddress2) {
+ body.push({
+ name: 'address2',
+ value: updateFields.streetAddress2,
+ });
+ }
+ if (updateFields.targetAccount) {
+ body.push({
+ name: 'hs_target_account',
+ value: updateFields.targetAccount,
+ });
+ }
+ if (updateFields.timezone) {
+ body.push({
+ name: 'timezone',
+ value: updateFields.timezone,
+ });
+ }
+ if (updateFields.totalMoneyRaised) {
+ body.push({
+ name: 'total_money_raised',
+ value: updateFields.totalMoneyRaised,
+ });
+ }
+ if (updateFields.twitterBio) {
+ body.push({
+ name: 'twitterbio',
+ value: updateFields.twitterBio,
+ });
+ }
+ if (updateFields.twitterFollowers) {
+ body.push({
+ name: 'twitterfollowers',
+ value: updateFields.twitterFollowers,
+ });
+ }
+ if (updateFields.twitterHandle) {
+ body.push({
+ name: 'twitterhandle',
+ value: updateFields.twitterHandle,
+ });
+ }
+ if (updateFields.type) {
+ body.push({
+ name: 'type',
+ value: updateFields.type,
+ });
+ }
+ if (updateFields.websiteUrl) {
+ body.push({
+ name: 'website',
+ value: updateFields.websiteUrl,
+ });
+ }
+ if (updateFields.webTechnologies) {
+ body.push({
+ name: 'web_technologies',
+ value: updateFields.webTechnologies,
+ });
+ }
+ if (updateFields.yearFounded) {
+ body.push({
+ name: 'founded_year',
+ value: updateFields.yearFounded,
+ });
+ }
+ const endpoint = `/companies/v2/companies/${companyId}`;
+ responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, { properties: body });
}
- if (updateFields.annualRevenue) {
- body.push({
- name: 'annualrevenue',
- value: (updateFields.annualRevenue as number).toString(),
- });
- }
- if (updateFields.city) {
- body.push({
- name: 'city',
- value: updateFields.city,
- });
- }
- if (updateFields.closeDate) {
- body.push({
- name: 'closedate',
- value: new Date(updateFields.closeDate as string).getTime(),
- });
- }
- if (updateFields.companyDomainName) {
- body.push({
- name: 'domain',
- value: updateFields.companyDomainName,
- });
- }
- if (updateFields.companyOwner) {
- body.push({
- name: 'hubspot_owner_id',
- value: updateFields.companyOwner,
- });
- }
- if (updateFields.countryRegion) {
- body.push({
- name: 'country',
- value: updateFields.countryRegion,
- });
- }
- if (updateFields.description) {
- body.push({
- name: 'description',
- value: updateFields.description,
- });
- }
- if (updateFields.facebookFans) {
- body.push({
- name: 'facebookfans',
- value: updateFields.facebookFans,
- });
- }
- if (updateFields.googlePlusPage) {
- body.push({
- name: 'googleplus_page',
- value: updateFields.googlePlusPage,
- });
- }
- if (updateFields.industry) {
- body.push({
- name: 'industry',
- value: updateFields.industry,
- });
- }
- if (updateFields.isPublic) {
- body.push({
- name: 'is_public',
- value: updateFields.isPublic,
- });
- }
- if (updateFields.leadStatus) {
- body.push({
- name: 'hs_lead_status',
- value: updateFields.leadStatus,
- });
- }
- if (updateFields.lifecycleStatus) {
- body.push({
- name: 'lifecyclestage',
- value: updateFields.lifecycleStatus,
- });
- }
- if (updateFields.linkedinBio) {
- body.push({
- name: 'linkedinbio',
- value: updateFields.linkedinBio,
- });
- }
- if (updateFields.linkedInCompanyPage) {
- body.push({
- name: 'linkedin_company_page',
- value: updateFields.linkedInCompanyPage,
- });
- }
- if (updateFields.numberOfEmployees) {
- body.push({
- name: 'numberofemployees',
- value: updateFields.numberOfEmployees,
- });
- }
- if (updateFields.originalSourceType) {
- body.push({
- name: 'hs_analytics_source',
- value: updateFields.originalSourceType,
- });
- }
- if (updateFields.phoneNumber) {
- body.push({
- name: 'phone',
- value: updateFields.phoneNumber,
- });
- }
- if (updateFields.postalCode) {
- body.push({
- name: 'zip',
- value: updateFields.postalCode,
- });
- }
- if (updateFields.stateRegion) {
- body.push({
- name: 'state',
- value: updateFields.stateRegion,
- });
- }
- if (updateFields.streetAddress) {
- body.push({
- name: 'address',
- value: updateFields.streetAddress,
- });
- }
- if (updateFields.streetAddress2) {
- body.push({
- name: 'address2',
- value: updateFields.streetAddress2,
- });
- }
- if (updateFields.targetAccount) {
- body.push({
- name: 'hs_target_account',
- value: updateFields.targetAccount,
- });
- }
- if (updateFields.timezone) {
- body.push({
- name: 'timezone',
- value: updateFields.timezone,
- });
- }
- if (updateFields.totalMoneyRaised) {
- body.push({
- name: 'total_money_raised',
- value: updateFields.totalMoneyRaised,
- });
- }
- if (updateFields.twitterBio) {
- body.push({
- name: 'twitterbio',
- value: updateFields.twitterBio,
- });
- }
- if (updateFields.twitterFollowers) {
- body.push({
- name: 'twitterfollowers',
- value: updateFields.twitterFollowers,
- });
- }
- if (updateFields.twitterHandle) {
- body.push({
- name: 'twitterhandle',
- value: updateFields.twitterHandle,
- });
- }
- if (updateFields.type) {
- body.push({
- name: 'type',
- value: updateFields.type,
- });
- }
- if (updateFields.websiteUrl) {
- body.push({
- name: 'website',
- value: updateFields.websiteUrl,
- });
- }
- if (updateFields.webTechnologies) {
- body.push({
- name: 'web_technologies',
- value: updateFields.webTechnologies,
- });
- }
- if (updateFields.yearFounded) {
- body.push({
- name: 'founded_year',
- value: updateFields.yearFounded,
- });
- }
- const endpoint = `/companies/v2/companies/${companyId}`;
- responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, { properties: body });
- }
- //https://developers.hubspot.com/docs/methods/companies/get_company
- if (operation === 'get') {
- const companyId = this.getNodeParameter('companyId', i) as string;
- const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
- if (additionalFields.includeMergeAudits) {
- qs.includeMergeAudits = additionalFields.includeMergeAudits as boolean;
- }
- const endpoint = `/companies/v2/companies/${companyId}`;
- responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
- }
- //https://developers.hubspot.com/docs/methods/companies/get-all-companies
- if (operation === 'getAll') {
- const options = this.getNodeParameter('options', i) as IDataObject;
- const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
- if (options.includeMergeAudits) {
- qs.includeMergeAudits = options.includeMergeAudits as boolean;
- }
- if (options.properties) {
- qs.properties = options.properties as string[];
- }
- if (options.propertiesWithHistory) {
- qs.propertiesWithHistory = (options.propertiesWithHistory as string).split(',');
- }
- const endpoint = `/companies/v2/companies/paged`;
- if (returnAll) {
- responseData = await hubspotApiRequestAllItems.call(this, 'companies', 'GET', endpoint, {}, qs);
- } else {
- qs.limit = this.getNodeParameter('limit', 0) as number;
+ //https://developers.hubspot.com/docs/methods/companies/get_company
+ if (operation === 'get') {
+ const companyId = this.getNodeParameter('companyId', i) as string;
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ if (additionalFields.includeMergeAudits) {
+ qs.includeMergeAudits = additionalFields.includeMergeAudits as boolean;
+ }
+ const endpoint = `/companies/v2/companies/${companyId}`;
responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
- responseData = responseData.companies;
+ }
+ //https://developers.hubspot.com/docs/methods/companies/get-all-companies
+ if (operation === 'getAll') {
+ const options = this.getNodeParameter('options', i) as IDataObject;
+ const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
+ if (options.includeMergeAudits) {
+ qs.includeMergeAudits = options.includeMergeAudits as boolean;
+ }
+ if (options.properties) {
+ qs.properties = options.properties as string[];
+ }
+ if (options.propertiesWithHistory) {
+ qs.propertiesWithHistory = (options.propertiesWithHistory as string).split(',');
+ }
+ const endpoint = `/companies/v2/companies/paged`;
+ if (returnAll) {
+ responseData = await hubspotApiRequestAllItems.call(this, 'companies', 'GET', endpoint, {}, qs);
+ } else {
+ qs.limit = this.getNodeParameter('limit', 0) as number;
+ responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
+ responseData = responseData.companies;
+ }
+ }
+ //https://developers.hubspot.com/docs/methods/companies/get_companies_modified
+ if (operation === 'getRecentlyCreated' || operation === 'getRecentlyModified') {
+ let endpoint;
+ const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
+ if (operation === 'getRecentlyCreated') {
+ endpoint = `/companies/v2/companies/recent/created`;
+ } else {
+ const filters = this.getNodeParameter('filters', i) as IDataObject;
+ if (filters.since) {
+ qs.since = new Date(filters.since as string).getTime();
+ }
+ endpoint = `/companies/v2/companies/recent/modified`;
+ }
+ if (returnAll) {
+ responseData = await hubspotApiRequestAllItems.call(this, 'results', 'GET', endpoint, {}, qs);
+ } else {
+ qs.count = this.getNodeParameter('limit', 0) as number;
+ responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
+ responseData = responseData.results;
+ }
+ }
+ //https://developers.hubspot.com/docs/methods/companies/search_companies_by_domain
+ if (operation === 'searchByDomain') {
+ const domain = this.getNodeParameter('domain', i) as string;
+ const options = this.getNodeParameter('options', i) as IDataObject;
+ const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
+ const body: IDataObject = {
+ requestOptions: {},
+ };
+ if (options.properties) {
+ body.requestOptions = { properties: options.properties as string[] };
+ }
+ const endpoint = `/companies/v2/domains/${domain}/companies`;
+ if (returnAll) {
+ responseData = await hubspotApiRequestAllItems.call(this, 'results', 'POST', endpoint, body);
+ } else {
+ body.limit = this.getNodeParameter('limit', 0) as number;
+ responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body);
+ responseData = responseData.results;
+ }
+ }
+ //https://developers.hubspot.com/docs/methods/companies/delete_company
+ if (operation === 'delete') {
+ const companyId = this.getNodeParameter('companyId', i) as string;
+ const endpoint = `/companies/v2/companies/${companyId}`;
+ responseData = await hubspotApiRequest.call(this, 'DELETE', endpoint);
}
}
- //https://developers.hubspot.com/docs/methods/companies/get_companies_modified
- if (operation === 'getRecentlyCreated' || operation === 'getRecentlyModified') {
- let endpoint;
- const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
- if (operation === 'getRecentlyCreated') {
- endpoint = `/companies/v2/companies/recent/created`;
- } else {
+ //https://developers.hubspot.com/docs/methods/deals/deals_overview
+ if (resource === 'deal') {
+ if (operation === 'create') {
+ const body: IDeal = {};
+ body.properties = [];
+ const association: IAssociation = {};
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ const stage = this.getNodeParameter('stage', i) as string;
+ if (stage) {
+ body.properties.push({
+ name: 'dealstage',
+ value: stage,
+ });
+ }
+ if (additionalFields.associatedCompany) {
+ association.associatedCompanyIds = additionalFields.associatedCompany as number[];
+ }
+ if (additionalFields.associatedVids) {
+ association.associatedVids = additionalFields.associatedVids as number[];
+ }
+ if (additionalFields.dealName) {
+ body.properties.push({
+ name: 'dealname',
+ value: additionalFields.dealName as string,
+ });
+ }
+ if (additionalFields.closeDate) {
+ body.properties.push({
+ name: 'closedate',
+ value: new Date(additionalFields.closeDate as string).getTime(),
+ });
+ }
+ if (additionalFields.amount) {
+ body.properties.push({
+ name: 'amount',
+ value: additionalFields.amount as string,
+ });
+ }
+ if (additionalFields.dealType) {
+ body.properties.push({
+ name: 'dealtype',
+ value: additionalFields.dealType as string,
+ });
+ }
+ if (additionalFields.pipeline) {
+ body.properties.push({
+ name: 'pipeline',
+ value: additionalFields.pipeline as string,
+ });
+ }
+ if (additionalFields.customPropertiesUi) {
+ const customProperties = (additionalFields.customPropertiesUi as IDataObject).customPropertiesValues as IDataObject[];
+ if (customProperties) {
+ for (const customProperty of customProperties) {
+ body.properties.push({
+ name: customProperty.property,
+ value: customProperty.value,
+ });
+ }
+ }
+ }
+ body.associations = association;
+ const endpoint = '/deals/v1/deal';
+ responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body);
+ }
+ if (operation === 'update') {
+ const body: IDeal = {};
+ body.properties = [];
+ const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
+ const dealId = this.getNodeParameter('dealId', i) as string;
+ if (updateFields.stage) {
+ body.properties.push({
+ name: 'dealstage',
+ value: updateFields.stage as string,
+ });
+ }
+ if (updateFields.dealName) {
+ body.properties.push({
+ name: 'dealname',
+ value: updateFields.dealName as string,
+ });
+ }
+ if (updateFields.closeDate) {
+ body.properties.push({
+ name: 'closedate',
+ value: new Date(updateFields.closeDate as string).getTime(),
+ });
+ }
+ if (updateFields.amount) {
+ body.properties.push({
+ name: 'amount',
+ value: updateFields.amount as string,
+ });
+ }
+ if (updateFields.dealType) {
+ body.properties.push({
+ name: 'dealtype',
+ value: updateFields.dealType as string,
+ });
+ }
+ if (updateFields.pipeline) {
+ body.properties.push({
+ name: 'pipeline',
+ value: updateFields.pipeline as string,
+ });
+ }
+ if (updateFields.customPropertiesUi) {
+ const customProperties = (updateFields.customPropertiesUi as IDataObject).customPropertiesValues as IDataObject[];
+ if (customProperties) {
+ for (const customProperty of customProperties) {
+ body.properties.push({
+ name: customProperty.property,
+ value: customProperty.value,
+ });
+ }
+ }
+ }
+ const endpoint = `/deals/v1/deal/${dealId}`;
+ responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, body);
+ }
+ if (operation === 'get') {
+ const dealId = this.getNodeParameter('dealId', i) as string;
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ if (additionalFields.includePropertyVersions) {
+ qs.includePropertyVersions = additionalFields.includePropertyVersions as boolean;
+ }
+ const endpoint = `/deals/v1/deal/${dealId}`;
+ responseData = await hubspotApiRequest.call(this, 'GET', endpoint);
+ }
+ if (operation === 'getAll') {
const filters = this.getNodeParameter('filters', i) as IDataObject;
+ const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
+ if (filters.includeAssociations) {
+ qs.includeAssociations = filters.includeAssociations as boolean;
+ }
+ if (filters.properties) {
+ qs.properties = (filters.properties as string).split(',');
+ }
+ if (filters.propertiesWithHistory) {
+ qs.propertiesWithHistory = (filters.propertiesWithHistory as string).split(',');
+ }
+ const endpoint = `/deals/v1/deal/paged`;
+ if (returnAll) {
+ responseData = await hubspotApiRequestAllItems.call(this, 'deals', 'GET', endpoint, {}, qs);
+ } else {
+ qs.limit = this.getNodeParameter('limit', 0) as number;
+ responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
+ responseData = responseData.deals;
+ }
+ }
+ if (operation === 'getRecentlyCreated' || operation === 'getRecentlyModified') {
+ let endpoint;
+ const filters = this.getNodeParameter('filters', i) as IDataObject;
+ const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
if (filters.since) {
qs.since = new Date(filters.since as string).getTime();
}
- endpoint = `/companies/v2/companies/recent/modified`;
+ if (filters.includePropertyVersions) {
+ qs.includePropertyVersions = filters.includePropertyVersions as boolean;
+ }
+ if (operation === 'getRecentlyCreated') {
+ endpoint = `/deals/v1/deal/recent/created`;
+ } else {
+ endpoint = `/deals/v1/deal/recent/modified`;
+ }
+ if (returnAll) {
+ responseData = await hubspotApiRequestAllItems.call(this, 'results', 'GET', endpoint, {}, qs);
+ } else {
+ qs.count = this.getNodeParameter('limit', 0) as number;
+ responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
+ responseData = responseData.results;
+ }
}
- if (returnAll) {
- responseData = await hubspotApiRequestAllItems.call(this, 'results', 'GET', endpoint, {}, qs);
- } else {
- qs.count = this.getNodeParameter('limit', 0) as number;
- responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
- responseData = responseData.results;
+ if (operation === 'delete') {
+ const dealId = this.getNodeParameter('dealId', i) as string;
+ const endpoint = `/deals/v1/deal/${dealId}`;
+ responseData = await hubspotApiRequest.call(this, 'DELETE', endpoint);
+ }
+ //https://developers.hubspot.com/docs/api/crm/search
+ if (operation === 'search') {
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
+ const filtersGroupsUi = this.getNodeParameter('filterGroupsUi', i) as IDataObject;
+ const sortBy = additionalFields.sortBy || 'createdate';
+ const direction = additionalFields.direction || 'DESCENDING';
+
+ const body: IDataObject = {
+ sorts: [
+ {
+ propertyName: sortBy,
+ direction,
+ },
+ ],
+ };
+
+ if (filtersGroupsUi) {
+ const filterGroupValues = (filtersGroupsUi as IDataObject).filterGroupsValues as IDataObject[];
+ if (filterGroupValues) {
+ body.filterGroups = [];
+ for (const filterGroupValue of filterGroupValues) {
+ if (filterGroupValue.filtersUi) {
+ const filterValues = (filterGroupValue.filtersUi as IDataObject).filterValues as IDataObject[];
+ if (filterValues) {
+ //@ts-ignore
+ body.filterGroups.push({ filters: filterValues });
+ }
+ }
+ }
+ }
+ }
+
+ Object.assign(body, additionalFields);
+
+ const endpoint = '/crm/v3/objects/deals/search';
+
+ if (returnAll) {
+
+ responseData = await hubspotApiRequestAllItems.call(this, 'results', 'POST', endpoint, body, qs);
+
+ } else {
+ qs.count = this.getNodeParameter('limit', 0) as number;
+ responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body, qs);
+ responseData = responseData.results;
+ }
}
}
- //https://developers.hubspot.com/docs/methods/companies/search_companies_by_domain
- if (operation === 'searchByDomain') {
- const domain = this.getNodeParameter('domain', i) as string;
- const options = this.getNodeParameter('options', i) as IDataObject;
- const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
- const body: IDataObject = {
- requestOptions: {},
- };
- if (options.properties) {
- body.requestOptions = { properties: options.properties as string[] };
+ //https://developers.hubspot.com/docs/methods/forms/forms_overview
+ if (resource === 'form') {
+ //https://developers.hubspot.com/docs/methods/forms/v2/get_fields
+ if (operation === 'getFields') {
+ const formId = this.getNodeParameter('formId', i) as string;
+ responseData = await hubspotApiRequest.call(this, 'GET', `/forms/v2/fields/${formId}`);
}
- const endpoint = `/companies/v2/domains/${domain}/companies`;
- if (returnAll) {
- responseData = await hubspotApiRequestAllItems.call(this, 'results', 'POST', endpoint, body);
- } else {
- body.limit = this.getNodeParameter('limit', 0) as number;
+ //https://developers.hubspot.com/docs/methods/forms/submit_form_v3
+ if (operation === 'submit') {
+ const formId = this.getNodeParameter('formId', i) as string;
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ const context = (this.getNodeParameter('contextUi', i) as IDataObject).contextValue as IDataObject;
+ const legalConsent = (this.getNodeParameter('lengalConsentUi', i) as IDataObject).lengalConsentValues as IDataObject;
+ const legitimateInteres = (this.getNodeParameter('lengalConsentUi', i) as IDataObject).legitimateInterestValues as IDataObject;
+ const { portalId } = await hubspotApiRequest.call(this, 'GET', `/forms/v2/forms/${formId}`);
+ const body: IForm = {
+ formId,
+ portalId,
+ legalConsentOptions: {},
+ fields: [],
+ };
+ if (additionalFields.submittedAt) {
+ body.submittedAt = new Date(additionalFields.submittedAt as string).getTime();
+ }
+ if (additionalFields.skipValidation) {
+ body.skipValidation = additionalFields.skipValidation as boolean;
+ }
+ const consent: IDataObject = {};
+ if (legalConsent) {
+ if (legalConsent.consentToProcess) {
+ consent!.consentToProcess = legalConsent.consentToProcess as boolean;
+ }
+ if (legalConsent.text) {
+ consent!.text = legalConsent.text as string;
+ }
+ if (legalConsent.communicationsUi) {
+ consent.communications = (legalConsent.communicationsUi as IDataObject).communicationValues as IDataObject;
+ }
+ }
+ body.legalConsentOptions!.consent = consent;
+ const fields: IDataObject = items[i].json;
+ for (const key of Object.keys(fields)) {
+ body.fields?.push({ name: key, value: fields[key] });
+ }
+ if (body.legalConsentOptions!.legitimateInterest) {
+ Object.assign(body, { legalConsentOptions: { legitimateInterest: legitimateInteres } });
+ }
+ if (context) {
+ Object.assign(body, { context });
+ }
+ const uri = `https://api.hsforms.com/submissions/v3/integration/submit/${portalId}/${formId}`;
+ responseData = await hubspotApiRequest.call(this, 'POST', '', body, {}, uri);
+ }
+ }
+ //https://developers.hubspot.com/docs/methods/tickets/tickets-overview
+ if (resource === 'ticket') {
+ //https://developers.hubspot.com/docs/methods/tickets/create-ticket
+ if (operation === 'create') {
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ const pipelineId = this.getNodeParameter('pipelineId', i) as string;
+ const stageId = this.getNodeParameter('stageId', i) as string;
+ const ticketName = this.getNodeParameter('ticketName', i) as string;
+ const body: IDataObject[] = [
+ {
+ name: 'hs_pipeline',
+ value: pipelineId,
+ },
+ {
+ name: 'hs_pipeline_stage',
+ value: stageId,
+ },
+ {
+ name: 'subject',
+ value: ticketName,
+ },
+ ];
+ if (additionalFields.category) {
+ body.push({
+ name: 'hs_ticket_category',
+ value: additionalFields.category as string,
+ });
+ }
+ if (additionalFields.closeDate) {
+ body.push({
+ name: 'closed_date',
+ value: new Date(additionalFields.closeDate as string).getTime(),
+ });
+ }
+ if (additionalFields.createDate) {
+ body.push({
+ name: 'createdate',
+ value: new Date(additionalFields.createDate as string).getTime(),
+ });
+ }
+ if (additionalFields.description) {
+ body.push({
+ name: 'content',
+ value: additionalFields.description as string,
+ });
+ }
+ if (additionalFields.priority) {
+ body.push({
+ name: 'hs_ticket_priority',
+ value: additionalFields.priority as string,
+ });
+ }
+ if (additionalFields.resolution) {
+ body.push({
+ name: 'hs_resolution',
+ value: additionalFields.resolution as string,
+ });
+ }
+ if (additionalFields.source) {
+ body.push({
+ name: 'source_type',
+ value: additionalFields.source as string,
+ });
+ }
+ if (additionalFields.ticketOwnerId) {
+ body.push({
+ name: 'hubspot_owner_id',
+ value: additionalFields.ticketOwnerId as string,
+ });
+ }
+ const endpoint = '/crm-objects/v1/objects/tickets';
responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body);
- responseData = responseData.results;
- }
- }
- //https://developers.hubspot.com/docs/methods/companies/delete_company
- if (operation === 'delete') {
- const companyId = this.getNodeParameter('companyId', i) as string;
- const endpoint = `/companies/v2/companies/${companyId}`;
- responseData = await hubspotApiRequest.call(this, 'DELETE', endpoint);
- }
- }
- //https://developers.hubspot.com/docs/methods/deals/deals_overview
- if (resource === 'deal') {
- if (operation === 'create') {
- const body: IDeal = {};
- body.properties = [];
- const association: IAssociation = {};
- const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
- const stage = this.getNodeParameter('stage', i) as string;
- if (stage) {
- body.properties.push({
- name: 'dealstage',
- value: stage,
- });
- }
- if (additionalFields.associatedCompany) {
- association.associatedCompanyIds = additionalFields.associatedCompany as number[];
- }
- if (additionalFields.associatedVids) {
- association.associatedVids = additionalFields.associatedVids as number[];
- }
- if (additionalFields.dealName) {
- body.properties.push({
- name: 'dealname',
- value: additionalFields.dealName as string,
- });
- }
- if (additionalFields.closeDate) {
- body.properties.push({
- name: 'closedate',
- value: new Date(additionalFields.closeDate as string).getTime(),
- });
- }
- if (additionalFields.amount) {
- body.properties.push({
- name: 'amount',
- value: additionalFields.amount as string,
- });
- }
- if (additionalFields.dealType) {
- body.properties.push({
- name: 'dealtype',
- value: additionalFields.dealType as string,
- });
- }
- if (additionalFields.pipeline) {
- body.properties.push({
- name: 'pipeline',
- value: additionalFields.pipeline as string,
- });
- }
- if (additionalFields.customPropertiesUi) {
- const customProperties = (additionalFields.customPropertiesUi as IDataObject).customPropertiesValues as IDataObject[];
- if (customProperties) {
- for (const customProperty of customProperties) {
- body.properties.push({
- name: customProperty.property,
- value: customProperty.value,
+
+ if (additionalFields.associatedCompanyIds) {
+ const companyAssociations: IDataObject[] = [];
+ for (const companyId of additionalFields.associatedCompanyIds as IDataObject[]) {
+ companyAssociations.push({
+ fromObjectId: responseData.objectId,
+ toObjectId: companyId,
+ category: 'HUBSPOT_DEFINED',
+ definitionId: 26,
});
}
+ await hubspotApiRequest.call(this, 'PUT', '/crm-associations/v1/associations/create-batch', companyAssociations);
}
- }
- body.associations = association;
- const endpoint = '/deals/v1/deal';
- responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body);
- }
- if (operation === 'update') {
- const body: IDeal = {};
- body.properties = [];
- const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
- const dealId = this.getNodeParameter('dealId', i) as string;
- if (updateFields.stage) {
- body.properties.push({
- name: 'dealstage',
- value: updateFields.stage as string,
- });
- }
- if (updateFields.dealName) {
- body.properties.push({
- name: 'dealname',
- value: updateFields.dealName as string,
- });
- }
- if (updateFields.closeDate) {
- body.properties.push({
- name: 'closedate',
- value: new Date(updateFields.closeDate as string).getTime(),
- });
- }
- if (updateFields.amount) {
- body.properties.push({
- name: 'amount',
- value: updateFields.amount as string,
- });
- }
- if (updateFields.dealType) {
- body.properties.push({
- name: 'dealtype',
- value: updateFields.dealType as string,
- });
- }
- if (updateFields.pipeline) {
- body.properties.push({
- name: 'pipeline',
- value: updateFields.pipeline as string,
- });
- }
- if (updateFields.customPropertiesUi) {
- const customProperties = (updateFields.customPropertiesUi as IDataObject).customPropertiesValues as IDataObject[];
- if (customProperties) {
- for (const customProperty of customProperties) {
- body.properties.push({
- name: customProperty.property,
- value: customProperty.value,
+
+ if (additionalFields.associatedContactIds) {
+ const contactAssociations: IDataObject[] = [];
+ for (const contactId of additionalFields.associatedContactIds as IDataObject[]) {
+ contactAssociations.push({
+ fromObjectId: responseData.objectId,
+ toObjectId: contactId,
+ category: 'HUBSPOT_DEFINED',
+ definitionId: 16,
});
}
+ await hubspotApiRequest.call(this, 'PUT', '/crm-associations/v1/associations/create-batch', contactAssociations);
}
}
- const endpoint = `/deals/v1/deal/${dealId}`;
- responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, body);
- }
- if (operation === 'get') {
- const dealId = this.getNodeParameter('dealId', i) as string;
- const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
- if (additionalFields.includePropertyVersions) {
- qs.includePropertyVersions = additionalFields.includePropertyVersions as boolean;
- }
- const endpoint = `/deals/v1/deal/${dealId}`;
- responseData = await hubspotApiRequest.call(this, 'GET', endpoint);
- }
- if (operation === 'getAll') {
- const filters = this.getNodeParameter('filters', i) as IDataObject;
- const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
- if (filters.includeAssociations) {
- qs.includeAssociations = filters.includeAssociations as boolean;
- }
- if (filters.properties) {
- qs.properties = (filters.properties as string).split(',');
- }
- if (filters.propertiesWithHistory) {
- qs.propertiesWithHistory = (filters.propertiesWithHistory as string).split(',');
- }
- const endpoint = `/deals/v1/deal/paged`;
- if (returnAll) {
- responseData = await hubspotApiRequestAllItems.call(this, 'deals', 'GET', endpoint, {}, qs);
- } else {
- qs.limit = this.getNodeParameter('limit', 0) as number;
+ //https://developers.hubspot.com/docs/methods/tickets/get_ticket_by_id
+ if (operation === 'get') {
+ const ticketId = this.getNodeParameter('ticketId', i) as string;
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ if (additionalFields.properties) {
+ qs.properties = additionalFields.properties as string[];
+ }
+ if (additionalFields.propertiesWithHistory) {
+ qs.propertiesWithHistory = (additionalFields.propertiesWithHistory as string).split(',');
+ }
+ if (additionalFields.includeDeleted) {
+ qs.includeDeleted = additionalFields.includeDeleted as boolean;
+ }
+ const endpoint = `/crm-objects/v1/objects/tickets/${ticketId}`;
responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
- responseData = responseData.deals;
}
- }
- if (operation === 'getRecentlyCreated' || operation === 'getRecentlyModified') {
- let endpoint;
- const filters = this.getNodeParameter('filters', i) as IDataObject;
- const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
- if (filters.since) {
- qs.since = new Date(filters.since as string).getTime();
- }
- if (filters.includePropertyVersions) {
- qs.includePropertyVersions = filters.includePropertyVersions as boolean;
- }
- if (operation === 'getRecentlyCreated') {
- endpoint = `/deals/v1/deal/recent/created`;
- } else {
- endpoint = `/deals/v1/deal/recent/modified`;
- }
- if (returnAll) {
- responseData = await hubspotApiRequestAllItems.call(this, 'results', 'GET', endpoint, {}, qs);
- } else {
- qs.count = this.getNodeParameter('limit', 0) as number;
- responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
- responseData = responseData.results;
- }
- }
- if (operation === 'delete') {
- const dealId = this.getNodeParameter('dealId', i) as string;
- const endpoint = `/deals/v1/deal/${dealId}`;
- responseData = await hubspotApiRequest.call(this, 'DELETE', endpoint);
- }
- }
- //https://developers.hubspot.com/docs/methods/forms/forms_overview
- if (resource === 'form') {
- //https://developers.hubspot.com/docs/methods/forms/v2/get_fields
- if (operation === 'getFields') {
- const formId = this.getNodeParameter('formId', i) as string;
- responseData = await hubspotApiRequest.call(this, 'GET', `/forms/v2/fields/${formId}`);
- }
- //https://developers.hubspot.com/docs/methods/forms/submit_form_v3
- if (operation === 'submit') {
- const formId = this.getNodeParameter('formId', i) as string;
- const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
- const context = (this.getNodeParameter('contextUi', i) as IDataObject).contextValue as IDataObject;
- const legalConsent = (this.getNodeParameter('lengalConsentUi', i) as IDataObject).lengalConsentValues as IDataObject;
- const legitimateInteres = (this.getNodeParameter('lengalConsentUi', i) as IDataObject).legitimateInterestValues as IDataObject;
- const { portalId } = await hubspotApiRequest.call(this, 'GET', `/forms/v2/forms/${formId}`);
- const body: IForm = {
- formId,
- portalId,
- legalConsentOptions: {},
- fields: [],
- };
- if (additionalFields.submittedAt) {
- body.submittedAt = new Date(additionalFields.submittedAt as string).getTime();
- }
- if (additionalFields.skipValidation) {
- body.skipValidation = additionalFields.skipValidation as boolean;
- }
- const consent: IDataObject = {};
- if (legalConsent) {
- if (legalConsent.consentToProcess) {
- consent!.consentToProcess = legalConsent.consentToProcess as boolean;
+ //https://developers.hubspot.com/docs/methods/tickets/get-all-tickets
+ if (operation === 'getAll') {
+ const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
+ const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
+ if (additionalFields.properties) {
+ qs.properties = additionalFields.properties as string[];
}
- if (legalConsent.text) {
- consent!.text = legalConsent.text as string;
+ if (additionalFields.propertiesWithHistory) {
+ qs.propertiesWithHistory = (additionalFields.propertiesWithHistory as string).split(',');
}
- if (legalConsent.communicationsUi) {
- consent.communications = (legalConsent.communicationsUi as IDataObject).communicationValues as IDataObject;
+ const endpoint = `/crm-objects/v1/objects/tickets/paged`;
+ if (returnAll) {
+ responseData = await hubspotApiRequestAllItems.call(this, 'objects', 'GET', endpoint, {}, qs);
+ } else {
+ qs.limit = this.getNodeParameter('limit', 0) as number;
+ responseData = await hubspotApiRequestAllItems.call(this, 'objects', 'GET', endpoint, {}, qs);
+ responseData = responseData.splice(0, qs.limit);
}
}
- body.legalConsentOptions!.consent = consent;
- const fields: IDataObject = items[i].json;
- for (const key of Object.keys(fields)) {
- body.fields?.push({ name: key, value: fields[key] });
+ //https://developers.hubspot.com/docs/methods/tickets/delete-ticket
+ if (operation === 'delete') {
+ const ticketId = this.getNodeParameter('ticketId', i) as string;
+ const endpoint = `/crm-objects/v1/objects/tickets/${ticketId}`;
+ await hubspotApiRequest.call(this, 'DELETE', endpoint);
+ responseData = { success: true };
}
- if (body.legalConsentOptions!.legitimateInterest) {
- Object.assign(body, { legalConsentOptions: { legitimateInterest: legitimateInteres } });
- }
- if (context) {
- Object.assign(body, { context });
- }
- const uri = `https://api.hsforms.com/submissions/v3/integration/submit/${portalId}/${formId}`;
- responseData = await hubspotApiRequest.call(this, 'POST', '', body, {}, uri);
- }
- }
- //https://developers.hubspot.com/docs/methods/tickets/tickets-overview
- if (resource === 'ticket') {
- //https://developers.hubspot.com/docs/methods/tickets/create-ticket
- if (operation === 'create') {
- const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
- const pipelineId = this.getNodeParameter('pipelineId', i) as string;
- const stageId = this.getNodeParameter('stageId', i) as string;
- const ticketName = this.getNodeParameter('ticketName', i) as string;
- const body: IDataObject[] = [
- {
- name: 'hs_pipeline',
- value: pipelineId,
- },
- {
- name: 'hs_pipeline_stage',
- value: stageId,
- },
- {
- name: 'subject',
- value: ticketName,
- },
- ];
- if (additionalFields.category) {
- body.push({
- name: 'hs_ticket_category',
- value: additionalFields.category as string,
- });
- }
- if (additionalFields.closeDate) {
- body.push({
- name: 'closed_date',
- value: new Date(additionalFields.closeDate as string).getTime(),
- });
- }
- if (additionalFields.createDate) {
- body.push({
- name: 'createdate',
- value: new Date(additionalFields.createDate as string).getTime(),
- });
- }
- if (additionalFields.description) {
- body.push({
- name: 'content',
- value: additionalFields.description as string,
- });
- }
- if (additionalFields.priority) {
- body.push({
- name: 'hs_ticket_priority',
- value: additionalFields.priority as string,
- });
- }
- if (additionalFields.resolution) {
- body.push({
- name: 'hs_resolution',
- value: additionalFields.resolution as string,
- });
- }
- if (additionalFields.source) {
- body.push({
- name: 'source_type',
- value: additionalFields.source as string,
- });
- }
- if (additionalFields.ticketOwnerId) {
- body.push({
- name: 'hubspot_owner_id',
- value: additionalFields.ticketOwnerId as string,
- });
- }
- const endpoint = '/crm-objects/v1/objects/tickets';
- responseData = await hubspotApiRequest.call(this, 'POST', endpoint, body);
-
- if (additionalFields.associatedCompanyIds) {
- const companyAssociations: IDataObject[] = [];
- for (const companyId of additionalFields.associatedCompanyIds as IDataObject[]) {
- companyAssociations.push({
- fromObjectId: responseData.objectId,
- toObjectId: companyId,
- category: 'HUBSPOT_DEFINED',
- definitionId: 26,
+ //https://developers.hubspot.com/docs/methods/tickets/update-ticket
+ if (operation === 'update') {
+ const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
+ const ticketId = this.getNodeParameter('ticketId', i) as string;
+ const body: IDataObject[] = [];
+ if (updateFields.pipelineId) {
+ body.push({
+ name: 'hs_pipeline',
+ value: updateFields.pipelineId as string,
});
}
- await hubspotApiRequest.call(this, 'PUT', '/crm-associations/v1/associations/create-batch', companyAssociations);
- }
-
- if (additionalFields.associatedContactIds) {
- const contactAssociations: IDataObject[] = [];
- for (const contactId of additionalFields.associatedContactIds as IDataObject[]) {
- contactAssociations.push({
- fromObjectId: responseData.objectId,
- toObjectId: contactId,
- category: 'HUBSPOT_DEFINED',
- definitionId: 16,
+ if (updateFields.ticketName) {
+ body.push({
+ name: 'subject',
+ value: updateFields.ticketName as string,
});
}
- await hubspotApiRequest.call(this, 'PUT', '/crm-associations/v1/associations/create-batch', contactAssociations);
- }
- }
- //https://developers.hubspot.com/docs/methods/tickets/get_ticket_by_id
- if (operation === 'get') {
- const ticketId = this.getNodeParameter('ticketId', i) as string;
- const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
- if (additionalFields.properties) {
- qs.properties = additionalFields.properties as string[];
- }
- if (additionalFields.propertiesWithHistory) {
- qs.propertiesWithHistory = (additionalFields.propertiesWithHistory as string).split(',');
- }
- if (additionalFields.includeDeleted) {
- qs.includeDeleted = additionalFields.includeDeleted as boolean;
- }
- const endpoint = `/crm-objects/v1/objects/tickets/${ticketId}`;
- responseData = await hubspotApiRequest.call(this, 'GET', endpoint, {}, qs);
- }
- //https://developers.hubspot.com/docs/methods/tickets/get-all-tickets
- if (operation === 'getAll') {
- const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
- const returnAll = this.getNodeParameter('returnAll', 0) as boolean;
- if (additionalFields.properties) {
- qs.properties = additionalFields.properties as string[];
- }
- if (additionalFields.propertiesWithHistory) {
- qs.propertiesWithHistory = (additionalFields.propertiesWithHistory as string).split(',');
- }
- const endpoint = `/crm-objects/v1/objects/tickets/paged`;
- if (returnAll) {
- responseData = await hubspotApiRequestAllItems.call(this, 'objects', 'GET', endpoint, {}, qs);
- } else {
- qs.limit = this.getNodeParameter('limit', 0) as number;
- responseData = await hubspotApiRequestAllItems.call(this, 'objects', 'GET', endpoint, {}, qs);
- responseData = responseData.splice(0, qs.limit);
- }
- }
- //https://developers.hubspot.com/docs/methods/tickets/delete-ticket
- if (operation === 'delete') {
- const ticketId = this.getNodeParameter('ticketId', i) as string;
- const endpoint = `/crm-objects/v1/objects/tickets/${ticketId}`;
- await hubspotApiRequest.call(this, 'DELETE', endpoint);
- responseData = { success: true };
- }
- //https://developers.hubspot.com/docs/methods/tickets/update-ticket
- if (operation === 'update') {
- const updateFields = this.getNodeParameter('updateFields', i) as IDataObject;
- const ticketId = this.getNodeParameter('ticketId', i) as string;
- const body: IDataObject[] = [];
- if (updateFields.pipelineId) {
- body.push({
- name: 'hs_pipeline',
- value: updateFields.pipelineId as string,
- });
- }
- if (updateFields.ticketName) {
- body.push({
- name: 'subject',
- value: updateFields.ticketName as string,
- });
- }
- if (updateFields.category) {
- body.push({
- name: 'hs_ticket_category',
- value: updateFields.category as string,
- });
- }
- if (updateFields.closeDate) {
- body.push({
- name: 'closed_date',
- value: new Date(updateFields.createDate as string).getTime(),
- });
- }
- if (updateFields.createDate) {
- body.push({
- name: 'createdate',
- value: new Date(updateFields.createDate as string).getTime(),
- });
- }
- if (updateFields.description) {
- body.push({
- name: 'content',
- value: updateFields.description as string,
- });
- }
- if (updateFields.priority) {
- body.push({
- name: 'hs_ticket_priority',
- value: updateFields.priority as string,
- });
- }
- if (updateFields.resolution) {
- body.push({
- name: 'hs_resolution',
- value: updateFields.resolution as string,
- });
- }
- if (updateFields.source) {
- body.push({
- name: 'source_type',
- value: updateFields.source as string,
- });
- }
- if (updateFields.ticketOwnerId) {
- body.push({
- name: 'hubspot_owner_id',
- value: updateFields.ticketOwnerId as string,
- });
- }
- const endpoint = `/crm-objects/v1/objects/tickets/${ticketId}`;
- responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, body);
-
- if (updateFields.associatedCompanyIds) {
- const companyAssociations: IDataObject[] = [];
- for (const companyId of updateFields.associatedCompanyIds as IDataObject[]) {
- companyAssociations.push({
- fromObjectId: responseData.objectId,
- toObjectId: companyId,
- category: 'HUBSPOT_DEFINED',
- definitionId: 26,
+ if (updateFields.category) {
+ body.push({
+ name: 'hs_ticket_category',
+ value: updateFields.category as string,
});
}
- await hubspotApiRequest.call(this, 'PUT', '/crm-associations/v1/associations/create-batch', companyAssociations);
- }
-
- if (updateFields.associatedContactIds) {
- const contactAssociations: IDataObject[] = [];
- for (const contactId of updateFields.associatedContactIds as IDataObject[]) {
- contactAssociations.push({
- fromObjectId: responseData.objectId,
- toObjectId: contactId,
- category: 'HUBSPOT_DEFINED',
- definitionId: 16,
+ if (updateFields.closeDate) {
+ body.push({
+ name: 'closed_date',
+ value: new Date(updateFields.createDate as string).getTime(),
});
}
- await hubspotApiRequest.call(this, 'PUT', '/crm-associations/v1/associations/create-batch', contactAssociations);
+ if (updateFields.createDate) {
+ body.push({
+ name: 'createdate',
+ value: new Date(updateFields.createDate as string).getTime(),
+ });
+ }
+ if (updateFields.description) {
+ body.push({
+ name: 'content',
+ value: updateFields.description as string,
+ });
+ }
+ if (updateFields.priority) {
+ body.push({
+ name: 'hs_ticket_priority',
+ value: updateFields.priority as string,
+ });
+ }
+ if (updateFields.resolution) {
+ body.push({
+ name: 'hs_resolution',
+ value: updateFields.resolution as string,
+ });
+ }
+ if (updateFields.source) {
+ body.push({
+ name: 'source_type',
+ value: updateFields.source as string,
+ });
+ }
+ if (updateFields.ticketOwnerId) {
+ body.push({
+ name: 'hubspot_owner_id',
+ value: updateFields.ticketOwnerId as string,
+ });
+ }
+ const endpoint = `/crm-objects/v1/objects/tickets/${ticketId}`;
+ responseData = await hubspotApiRequest.call(this, 'PUT', endpoint, body);
+
+ if (updateFields.associatedCompanyIds) {
+ const companyAssociations: IDataObject[] = [];
+ for (const companyId of updateFields.associatedCompanyIds as IDataObject[]) {
+ companyAssociations.push({
+ fromObjectId: responseData.objectId,
+ toObjectId: companyId,
+ category: 'HUBSPOT_DEFINED',
+ definitionId: 26,
+ });
+ }
+ await hubspotApiRequest.call(this, 'PUT', '/crm-associations/v1/associations/create-batch', companyAssociations);
+ }
+
+ if (updateFields.associatedContactIds) {
+ const contactAssociations: IDataObject[] = [];
+ for (const contactId of updateFields.associatedContactIds as IDataObject[]) {
+ contactAssociations.push({
+ fromObjectId: responseData.objectId,
+ toObjectId: contactId,
+ category: 'HUBSPOT_DEFINED',
+ definitionId: 16,
+ });
+ }
+ await hubspotApiRequest.call(this, 'PUT', '/crm-associations/v1/associations/create-batch', contactAssociations);
+ }
}
}
- }
- if (Array.isArray(responseData)) {
- returnData.push.apply(returnData, responseData as IDataObject[]);
- } else {
- returnData.push(responseData as IDataObject);
+ if (Array.isArray(responseData)) {
+ returnData.push.apply(returnData, responseData as IDataObject[]);
+ } else {
+ returnData.push(responseData as IDataObject);
+ }
}
}
return [this.helpers.returnJsonArray(returnData)];