diff --git a/packages/nodes-base/credentials/HubspotDeveloperApi.credentials.ts b/packages/nodes-base/credentials/HubspotDeveloperApi.credentials.ts index 0de15fe956038..d71b49d095bec 100644 --- a/packages/nodes-base/credentials/HubspotDeveloperApi.credentials.ts +++ b/packages/nodes-base/credentials/HubspotDeveloperApi.credentials.ts @@ -4,7 +4,12 @@ import { } from 'n8n-workflow'; const scopes = [ - 'contacts', + 'crm.objects.contacts.read', + 'crm.schemas.contacts.read', + 'crm.objects.companies.read', + 'crm.schemas.companies.read', + 'crm.objects.deals.read', + 'crm.schemas.deals.read', ]; export class HubspotDeveloperApi implements ICredentialType { diff --git a/packages/nodes-base/credentials/HubspotOAuth2Api.credentials.ts b/packages/nodes-base/credentials/HubspotOAuth2Api.credentials.ts index 52187d888cd2a..8c5402f0ce5c2 100644 --- a/packages/nodes-base/credentials/HubspotOAuth2Api.credentials.ts +++ b/packages/nodes-base/credentials/HubspotOAuth2Api.credentials.ts @@ -4,7 +4,16 @@ import { } from 'n8n-workflow'; const scopes = [ - 'contacts', + 'crm.schemas.deals.read', + 'crm.objects.owners.read', + 'crm.objects.contacts.write', + 'crm.objects.companies.write', + 'crm.objects.companies.read', + 'crm.objects.deals.read', + 'crm.schemas.contacts.read', + 'crm.objects.deals.write', + 'crm.objects.contacts.read', + 'crm.schemas.companies.read', 'forms', 'tickets', ]; diff --git a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts index b430e54e3f1e3..bebad7777f1b5 100644 --- a/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Hubspot/GenericFunctions.ts @@ -39,12 +39,16 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions return await this.helpers.request!(options); } else if (authenticationMethod === 'developerApi') { - const credentials = await this.getCredentials('hubspotDeveloperApi'); + if (endpoint.includes('webhooks')) { - options.qs.hapikey = credentials!.apiKey as string; - return await this.helpers.request!(options); + const credentials = await this.getCredentials('hubspotDeveloperApi'); + options.qs.hapikey = credentials!.apiKey as string; + return await this.helpers.request!(options); + + } else { + return await this.helpers.requestOAuth2!.call(this, 'hubspotDeveloperApi', options, { tokenType: 'Bearer', includeCredentialsOnRefreshOnBody: true }); + } } else { - // @ts-ignore return await this.helpers.requestOAuth2!.call(this, 'hubspotOAuth2Api', options, { tokenType: 'Bearer', includeCredentialsOnRefreshOnBody: true }); } } catch (error) { diff --git a/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts b/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts index fce1e0e40a700..f522a2d8568a4 100644 --- a/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts +++ b/packages/nodes-base/nodes/Hubspot/HubspotTrigger.node.ts @@ -143,6 +143,9 @@ export class HubspotTrigger implements INodeType { name: 'property', type: 'options', typeOptions: { + loadOptionsDependsOn: [ + 'contact.propertyChange', + ], loadOptionsMethod: 'getContactProperties', }, displayOptions: { @@ -160,6 +163,9 @@ export class HubspotTrigger implements INodeType { name: 'property', type: 'options', typeOptions: { + loadOptionsDependsOn: [ + 'company.propertyChange', + ], loadOptionsMethod: 'getCompanyProperties', }, displayOptions: { @@ -177,6 +183,9 @@ export class HubspotTrigger implements INodeType { name: 'property', type: 'options', typeOptions: { + loadOptionsDependsOn: [ + 'deal.propertyChange', + ], loadOptionsMethod: 'getDealProperties', }, displayOptions: { @@ -220,51 +229,48 @@ export class HubspotTrigger implements INodeType { // select them easily async getContactProperties(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; - for (const field of contactFields) { + const endpoint = '/properties/v2/contacts/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: capitalCase(field.label), - value: field.id, + name: propertyName, + value: propertyId, }); } - returnData.sort((a, b) => { - if (a.name < b.name) { return -1; } - if (a.name > b.name) { return 1; } - return 0; - }); return returnData; }, // Get all the available companies to display them to user so that he can // select them easily async getCompanyProperties(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; - for (const field of companyFields) { + const endpoint = '/properties/v2/companies/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: capitalCase(field.label), - value: field.id, + name: propertyName, + value: propertyId, }); } - returnData.sort((a, b) => { - if (a.name < b.name) { return -1; } - if (a.name > b.name) { return 1; } - return 0; - }); return returnData; }, // Get all the available deals to display them to user so that he can // select them easily async getDealProperties(this: ILoadOptionsFunctions): Promise { const returnData: INodePropertyOptions[] = []; - for (const field of dealFields) { + 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: capitalCase(field.label), - value: field.id, + name: propertyName, + value: propertyId, }); } - returnData.sort((a, b) => { - if (a.name < b.name) { return -1; } - if (a.name > b.name) { return 1; } - return 0; - }); return returnData; }, },