mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 05:04:05 -08:00
⚡ Small improvements to Hubspot Trigger Node
This commit is contained in:
parent
e213387103
commit
3d2e90ed18
|
@ -12,12 +12,11 @@ import {
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise<any> { // tslint:disable-line:no-any
|
||||||
let credentials;
|
|
||||||
try {
|
const node = this.getNode();
|
||||||
credentials = this.getCredentials('hubspotApi');
|
const credentialName = Object.keys(node.credentials!)[0];
|
||||||
} catch (exception) {
|
const credentials = this.getCredentials(credentialName);
|
||||||
credentials = this.getCredentials('hubspotDeveloperApi');
|
|
||||||
}
|
|
||||||
query!.hapikey = credentials!.apiKey as string;
|
query!.hapikey = credentials!.apiKey as string;
|
||||||
const options: OptionsWithUri = {
|
const options: OptionsWithUri = {
|
||||||
method,
|
method,
|
||||||
|
@ -31,13 +30,8 @@ export async function hubspotApiRequest(this: IHookFunctions | IExecuteFunctions
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error)
|
const errorMessage = error.response.body.message || error.response.body.Message || error.message;
|
||||||
const errorMessage = error.response.body.message || error.response.body.Message;
|
throw new Error(`Hubspot error response [${error.statusCode}]: ${errorMessage}`);
|
||||||
|
|
||||||
if (errorMessage !== undefined) {
|
|
||||||
throw errorMessage;
|
|
||||||
}
|
|
||||||
throw error.response.body;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,7 +191,7 @@ export class HubspotTrigger implements INodeType {
|
||||||
'deal.propertyChange',
|
'deal.propertyChange',
|
||||||
];
|
];
|
||||||
let endpoint = `/webhooks/v1/${app}/settings`;
|
let endpoint = `/webhooks/v1/${app}/settings`;
|
||||||
let body = {
|
let body: IDataObject = {
|
||||||
webhookUrl,
|
webhookUrl,
|
||||||
maxConcurrentRequests: additionalFields.maxConcurrentRequests || 5,
|
maxConcurrentRequests: additionalFields.maxConcurrentRequests || 5,
|
||||||
};
|
};
|
||||||
|
@ -199,7 +199,6 @@ export class HubspotTrigger implements INodeType {
|
||||||
|
|
||||||
endpoint = `/webhooks/v1/${app}/subscriptions`;
|
endpoint = `/webhooks/v1/${app}/subscriptions`;
|
||||||
body = {
|
body = {
|
||||||
//@ts-ignore
|
|
||||||
subscriptionDetails: {
|
subscriptionDetails: {
|
||||||
subscriptionType: event,
|
subscriptionType: event,
|
||||||
},
|
},
|
||||||
|
@ -246,11 +245,11 @@ export class HubspotTrigger implements INodeType {
|
||||||
|
|
||||||
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||||
const credentials = this.getCredentials('hubspotDeveloperApi');
|
const credentials = this.getCredentials('hubspotDeveloperApi');
|
||||||
const req = this.getRequestObject()
|
const req = this.getRequestObject();
|
||||||
const bodyData = req.body;
|
const bodyData = req.body;
|
||||||
const headerData = this.getHeaderData();
|
const headerData = this.getHeaderData();
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
if (headerData['x-hubspot-signature'] == undefined) {
|
if (headerData['x-hubspot-signature'] === undefined) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const hash = `${credentials!.clientSecret}${JSON.stringify(bodyData)}`;
|
const hash = `${credentials!.clientSecret}${JSON.stringify(bodyData)}`;
|
||||||
|
|
Loading…
Reference in a new issue