mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat(Hubspot Node): enable hubspot credentials for http predefined types (#3686)
This commit is contained in:
parent
fc87650180
commit
b5c40e6294
|
@ -1,4 +1,4 @@
|
||||||
import { ICredentialType, INodeProperties } from 'n8n-workflow';
|
import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';
|
||||||
|
|
||||||
export class HubspotApi implements ICredentialType {
|
export class HubspotApi implements ICredentialType {
|
||||||
name = 'hubspotApi';
|
name = 'hubspotApi';
|
||||||
|
@ -12,4 +12,20 @@ export class HubspotApi implements ICredentialType {
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
authenticate: IAuthenticateGeneric = {
|
||||||
|
type: 'generic',
|
||||||
|
properties: {
|
||||||
|
qs: {
|
||||||
|
hapikey: '={{$credentials.apiKey}}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
test: ICredentialTestRequest = {
|
||||||
|
request: {
|
||||||
|
baseURL: 'https://api.hubapi.com',
|
||||||
|
url: '/account-info/v3/details',
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { ICredentialType, INodeProperties } from 'n8n-workflow';
|
import { IAuthenticateGeneric, ICredentialTestRequest, ICredentialType, INodeProperties } from 'n8n-workflow';
|
||||||
|
|
||||||
export class HubspotAppToken implements ICredentialType {
|
export class HubspotAppToken implements ICredentialType {
|
||||||
name = 'hubspotAppToken';
|
name = 'hubspotAppToken';
|
||||||
|
@ -12,4 +12,20 @@ export class HubspotAppToken implements ICredentialType {
|
||||||
default: '',
|
default: '',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
authenticate: IAuthenticateGeneric = {
|
||||||
|
type: 'generic',
|
||||||
|
properties: {
|
||||||
|
headers: {
|
||||||
|
Authorization: '=Bearer {{$credentials.appToken}}',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
test: ICredentialTestRequest = {
|
||||||
|
request: {
|
||||||
|
baseURL: 'https://api.hubapi.com',
|
||||||
|
url: '/account-info/v3/details',
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,16 +44,9 @@ export async function hubspotApiRequest(
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (authenticationMethod === 'apiKey') {
|
if (authenticationMethod === 'apiKey' || authenticationMethod === 'appToken') {
|
||||||
const credentials = await this.getCredentials('hubspotApi');
|
const credentialType = authenticationMethod === 'apiKey' ? 'hubspotApi' : 'hubspotAppToken';
|
||||||
|
return this.helpers.requestWithAuthentication.call(this, credentialType, options);
|
||||||
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);
|
|
||||||
} else if (authenticationMethod === 'developerApi') {
|
} else if (authenticationMethod === 'developerApi') {
|
||||||
if (endpoint.includes('webhooks')) {
|
if (endpoint.includes('webhooks')) {
|
||||||
const credentials = await this.getCredentials('hubspotDeveloperApi');
|
const credentials = await this.getCredentials('hubspotDeveloperApi');
|
||||||
|
|
Loading…
Reference in a new issue