mirror of
https://github.com/n8n-io/n8n.git
synced 2024-09-20 06:47:32 -07:00
fix(Toggl Trigger Node): Update API version (#10207)
This commit is contained in:
parent
09c3a8b367
commit
9bdb1d6dca
|
@ -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 {
|
export class TogglApi implements ICredentialType {
|
||||||
name = 'togglApi';
|
name = 'togglApi';
|
||||||
|
@ -9,7 +14,7 @@ export class TogglApi implements ICredentialType {
|
||||||
|
|
||||||
properties: INodeProperties[] = [
|
properties: INodeProperties[] = [
|
||||||
{
|
{
|
||||||
displayName: 'Username',
|
displayName: 'Email Address',
|
||||||
name: 'username',
|
name: 'username',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
default: '',
|
default: '',
|
||||||
|
@ -22,4 +27,21 @@ export class TogglApi implements ICredentialType {
|
||||||
default: '',
|
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',
|
||||||
|
},
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,21 +24,10 @@ export async function togglApiRequest(
|
||||||
query?: IDataObject,
|
query?: IDataObject,
|
||||||
uri?: string,
|
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 = {
|
const options: IRequestOptions = {
|
||||||
headers: headerWithAuthentication,
|
|
||||||
method,
|
method,
|
||||||
qs: query,
|
qs: query,
|
||||||
uri: uri || `https://api.track.toggl.com/api/v8${resource}`,
|
uri: uri || `https://api.track.toggl.com/api/v9/me${resource}`,
|
||||||
body,
|
body,
|
||||||
json: true,
|
json: true,
|
||||||
};
|
};
|
||||||
|
@ -46,7 +35,7 @@ export async function togglApiRequest(
|
||||||
delete options.body;
|
delete options.body;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return await this.helpers.request(options);
|
return await this.helpers.requestWithAuthentication.call(this, 'togglApi', options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new NodeApiError(this.getNode(), error as JsonObject);
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import type {
|
||||||
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
|
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
|
||||||
|
|
||||||
import moment from 'moment-timezone';
|
import moment from 'moment-timezone';
|
||||||
|
import { DateTime } from 'luxon';
|
||||||
import { togglApiRequest } from './GenericFunctions';
|
import { togglApiRequest } from './GenericFunctions';
|
||||||
|
|
||||||
export class TogglTrigger implements INodeType {
|
export class TogglTrigger implements INodeType {
|
||||||
|
@ -62,7 +63,7 @@ export class TogglTrigger implements INodeType {
|
||||||
|
|
||||||
const qs: IDataObject = {};
|
const qs: IDataObject = {};
|
||||||
let timeEntries = [];
|
let timeEntries = [];
|
||||||
qs.start_date = webhookData.lastTimeChecked;
|
qs.start_date = webhookData.lastTimeChecked ?? DateTime.now().toISODate();
|
||||||
qs.end_date = moment().format();
|
qs.end_date = moment().format();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue