mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
⚡ Minor improvements to AcuityScheduling-Node
This commit is contained in:
parent
bde233b9c4
commit
c5ad3eecca
|
@ -17,7 +17,7 @@ import {
|
||||||
export class AcuitySchedulingTrigger implements INodeType {
|
export class AcuitySchedulingTrigger implements INodeType {
|
||||||
description: INodeTypeDescription = {
|
description: INodeTypeDescription = {
|
||||||
displayName: 'Acuity Scheduling Trigger',
|
displayName: 'Acuity Scheduling Trigger',
|
||||||
name: 'acuityScheduling',
|
name: 'acuitySchedulingTrigger',
|
||||||
icon: 'file:acuityScheduling.png',
|
icon: 'file:acuityScheduling.png',
|
||||||
group: ['trigger'],
|
group: ['trigger'],
|
||||||
version: 1,
|
version: 1,
|
||||||
|
@ -77,6 +77,13 @@ export class AcuitySchedulingTrigger implements INodeType {
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Resolve Data',
|
||||||
|
name: 'resolveData',
|
||||||
|
type: 'boolean',
|
||||||
|
default: true,
|
||||||
|
description: 'By default does the webhook-data only contain the ID of the object.<br />If this option gets activated it will resolve the data automatically.',
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
@ -127,10 +134,30 @@ export class AcuitySchedulingTrigger implements INodeType {
|
||||||
|
|
||||||
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
async webhook(this: IWebhookFunctions): Promise<IWebhookResponseData> {
|
||||||
const req = this.getRequestObject();
|
const req = this.getRequestObject();
|
||||||
|
|
||||||
|
const resolveData = this.getNodeParameter('resolveData', false) as boolean;
|
||||||
|
|
||||||
|
if (resolveData === false) {
|
||||||
|
// Return the data as it got received
|
||||||
|
return {
|
||||||
|
workflowData: [
|
||||||
|
this.helpers.returnJsonArray(req.body),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Resolve the data by requesting the information via API
|
||||||
|
const event = this.getNodeParameter('event', false) as string;
|
||||||
|
const eventType = event.split('.').shift();
|
||||||
|
const endpoint = `/${eventType}s/${req.body.id}`;
|
||||||
|
const responseData = await acuitySchedulingApiRequest.call(this, 'GET', endpoint, {});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
workflowData: [
|
workflowData: [
|
||||||
this.helpers.returnJsonArray(req.body),
|
this.helpers.returnJsonArray(responseData),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,12 +14,14 @@ export async function acuitySchedulingApiRequest(this: IHookFunctions | IExecute
|
||||||
throw new Error('No credentials got returned!');
|
throw new Error('No credentials got returned!');
|
||||||
}
|
}
|
||||||
|
|
||||||
const base64Key = Buffer.from(`${credentials.userId}:${credentials.apiKey}`).toString('base64');
|
const options: OptionsWithUri = {
|
||||||
let options: OptionsWithUri = {
|
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Basic ${base64Key}`,
|
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
},
|
},
|
||||||
|
auth: {
|
||||||
|
user: credentials.userId as string,
|
||||||
|
password: credentials.apiKey as string,
|
||||||
|
},
|
||||||
method,
|
method,
|
||||||
qs,
|
qs,
|
||||||
body,
|
body,
|
||||||
|
@ -29,6 +31,12 @@ export async function acuitySchedulingApiRequest(this: IHookFunctions | IExecute
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request!(options);
|
return await this.helpers.request!(options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error('Acuity Scheduling Error: ' + error.message);
|
|
||||||
|
let errorMessage = error.message;
|
||||||
|
if (error.response.body && error.response.body.message) {
|
||||||
|
errorMessage = `[${error.response.body.status_code}] ${error.response.body.message}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error('Acuity Scheduling Error: ' + errorMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue