From 9bdb1d6dca43fe491c5eb96f093b7eec4509eaff Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 21 Aug 2024 10:43:48 +0100 Subject: [PATCH] fix(Toggl Trigger Node): Update API version (#10207) --- .../credentials/TogglApi.credentials.ts | 26 +++++++++++++++++-- .../nodes/Toggl/GenericFunctions.ts | 15 ++--------- .../nodes/Toggl/TogglTrigger.node.ts | 3 ++- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/packages/nodes-base/credentials/TogglApi.credentials.ts b/packages/nodes-base/credentials/TogglApi.credentials.ts index eb4eb5b4a6..30145b168c 100644 --- a/packages/nodes-base/credentials/TogglApi.credentials.ts +++ b/packages/nodes-base/credentials/TogglApi.credentials.ts @@ -1,4 +1,9 @@ -import type { ICredentialType, INodeProperties } from 'n8n-workflow'; +import type { + IAuthenticateGeneric, + ICredentialTestRequest, + ICredentialType, + INodeProperties, +} from 'n8n-workflow'; export class TogglApi implements ICredentialType { name = 'togglApi'; @@ -9,7 +14,7 @@ export class TogglApi implements ICredentialType { properties: INodeProperties[] = [ { - displayName: 'Username', + displayName: 'Email Address', name: 'username', type: 'string', default: '', @@ -22,4 +27,21 @@ export class TogglApi implements ICredentialType { default: '', }, ]; + + authenticate: IAuthenticateGeneric = { + type: 'generic', + properties: { + auth: { + username: '={{$credentials.username}}', + password: '={{$credentials.password}}', + }, + }, + }; + + test: ICredentialTestRequest = { + request: { + baseURL: 'https://api.track.toggl.com/api/v9', + url: '/me', + }, + }; } diff --git a/packages/nodes-base/nodes/Toggl/GenericFunctions.ts b/packages/nodes-base/nodes/Toggl/GenericFunctions.ts index 48b018a215..6b766730c8 100644 --- a/packages/nodes-base/nodes/Toggl/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Toggl/GenericFunctions.ts @@ -24,21 +24,10 @@ export async function togglApiRequest( query?: IDataObject, uri?: string, ) { - const credentials = await this.getCredentials('togglApi'); - const headerWithAuthentication = Object.assign( - {}, - { - Authorization: ` Basic ${Buffer.from( - `${credentials.username}:${credentials.password}`, - ).toString('base64')}`, - }, - ); - const options: IRequestOptions = { - headers: headerWithAuthentication, method, qs: query, - uri: uri || `https://api.track.toggl.com/api/v8${resource}`, + uri: uri || `https://api.track.toggl.com/api/v9/me${resource}`, body, json: true, }; @@ -46,7 +35,7 @@ export async function togglApiRequest( delete options.body; } try { - return await this.helpers.request(options); + return await this.helpers.requestWithAuthentication.call(this, 'togglApi', options); } catch (error) { throw new NodeApiError(this.getNode(), error as JsonObject); } diff --git a/packages/nodes-base/nodes/Toggl/TogglTrigger.node.ts b/packages/nodes-base/nodes/Toggl/TogglTrigger.node.ts index fcfcf87846..a95d35ce13 100644 --- a/packages/nodes-base/nodes/Toggl/TogglTrigger.node.ts +++ b/packages/nodes-base/nodes/Toggl/TogglTrigger.node.ts @@ -9,6 +9,7 @@ import type { import { NodeApiError, NodeOperationError } from 'n8n-workflow'; import moment from 'moment-timezone'; +import { DateTime } from 'luxon'; import { togglApiRequest } from './GenericFunctions'; export class TogglTrigger implements INodeType { @@ -62,7 +63,7 @@ export class TogglTrigger implements INodeType { const qs: IDataObject = {}; let timeEntries = []; - qs.start_date = webhookData.lastTimeChecked; + qs.start_date = webhookData.lastTimeChecked ?? DateTime.now().toISODate(); qs.end_date = moment().format(); try {