diff --git a/packages/nodes-base/nodes/AcuityScheduling/AcuitySchedulingTrigger.node.ts b/packages/nodes-base/nodes/AcuityScheduling/AcuitySchedulingTrigger.node.ts index dc9a9b072d..2166b5cc85 100644 --- a/packages/nodes-base/nodes/AcuityScheduling/AcuitySchedulingTrigger.node.ts +++ b/packages/nodes-base/nodes/AcuityScheduling/AcuitySchedulingTrigger.node.ts @@ -17,7 +17,7 @@ import { export class AcuitySchedulingTrigger implements INodeType { description: INodeTypeDescription = { displayName: 'Acuity Scheduling Trigger', - name: 'acuityScheduling', + name: 'acuitySchedulingTrigger', icon: 'file:acuityScheduling.png', group: ['trigger'], 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.
If this option gets activated it will resolve the data automatically.', + }, ], }; // @ts-ignore @@ -127,10 +134,30 @@ export class AcuitySchedulingTrigger implements INodeType { async webhook(this: IWebhookFunctions): Promise { 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 { workflowData: [ - this.helpers.returnJsonArray(req.body), + this.helpers.returnJsonArray(responseData), ], }; + + } } diff --git a/packages/nodes-base/nodes/AcuityScheduling/GenericFunctions.ts b/packages/nodes-base/nodes/AcuityScheduling/GenericFunctions.ts index e14ff589d5..9a2d0fc597 100644 --- a/packages/nodes-base/nodes/AcuityScheduling/GenericFunctions.ts +++ b/packages/nodes-base/nodes/AcuityScheduling/GenericFunctions.ts @@ -14,12 +14,14 @@ export async function acuitySchedulingApiRequest(this: IHookFunctions | IExecute throw new Error('No credentials got returned!'); } - const base64Key = Buffer.from(`${credentials.userId}:${credentials.apiKey}`).toString('base64'); - let options: OptionsWithUri = { + const options: OptionsWithUri = { headers: { - Authorization: `Basic ${base64Key}`, 'Content-Type': 'application/json', }, + auth: { + user: credentials.userId as string, + password: credentials.apiKey as string, + }, method, qs, body, @@ -29,6 +31,12 @@ export async function acuitySchedulingApiRequest(this: IHookFunctions | IExecute try { return await this.helpers.request!(options); } 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); } }