Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Hubspot Node): enable hubspot credentials for http predefined types #3686

Merged
merged 4 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/nodes-base/credentials/HubspotApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICredentialType, INodeProperties } from 'n8n-workflow';
import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';

export class HubspotApi implements ICredentialType {
name = 'hubspotApi';
Expand All @@ -12,4 +12,20 @@ export class HubspotApi implements ICredentialType {
default: '',
},
];

authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
qs: {
hapikey: '={{$credentials.apiKey}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.hubapi.com',
url: '/account-info/v3/details',
},
};
}
Joffcom marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 17 additions & 1 deletion packages/nodes-base/credentials/HubspotAppToken.credentials.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ICredentialType, INodeProperties } from 'n8n-workflow';
import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';

export class HubspotAppToken implements ICredentialType {
name = 'hubspotAppToken';
Expand All @@ -12,4 +12,20 @@ export class HubspotAppToken implements ICredentialType {
default: '',
},
];

authenticate: IAuthenticateGeneric = {
type: 'generic',
properties: {
headers: {
Authorization: '=Bearer {{$credentials.appToken}}',
},
},
};

test: ICredentialTestRequest = {
request: {
baseURL: 'https://api.hubapi.com',
url: '/account-info/v3/details',
},
};
}
Joffcom marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 3 additions & 10 deletions packages/nodes-base/nodes/Hubspot/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,9 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions
};

try {
if (authenticationMethod === 'apiKey') {
const credentials = await this.getCredentials('hubspotApi');

options.qs.hapikey = credentials.apiKey as string;
return await this.helpers.request!(options);
} else if (authenticationMethod === 'appToken') {
const credentials = await this.getCredentials('hubspotAppToken');

options.headers!['Authorization'] = `Bearer ${credentials.appToken}`;
return await this.helpers.request!(options);
if (authenticationMethod === 'apiKey' || authenticationMethod === 'appToken') {
const credentialType = authenticationMethod === 'apiKey' ? 'hubspotApi' : 'hubspotAppToken';
return this.helpers.requestWithAuthentication.call(this, credentialType, options);
} else if (authenticationMethod === 'developerApi') {
if (endpoint.includes('webhooks')) {

Expand Down