Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Toggl Trigger Node): Update API version #10207

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions packages/nodes-base/credentials/TogglApi.credentials.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -9,7 +14,7 @@ export class TogglApi implements ICredentialType {

properties: INodeProperties[] = [
{
displayName: 'Username',
displayName: 'Email Address',
name: 'username',
type: 'string',
default: '',
Expand All @@ -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',
},
};
}
15 changes: 2 additions & 13 deletions packages/nodes-base/nodes/Toggl/GenericFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,18 @@ 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,
};
if (Object.keys(options.body as IDataObject).length === 0) {
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);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/nodes-base/nodes/Toggl/TogglTrigger.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Loading