diff --git a/packages/nodes-base/credentials/TwakeCloudApi.credentials.ts b/packages/nodes-base/credentials/TwakeCloudApi.credentials.ts index 798bb9efe..93abdec47 100644 --- a/packages/nodes-base/credentials/TwakeCloudApi.credentials.ts +++ b/packages/nodes-base/credentials/TwakeCloudApi.credentials.ts @@ -1,4 +1,6 @@ import { + IAuthenticateBearer, + ICredentialTestRequest, ICredentialType, INodeProperties, } from 'n8n-workflow'; @@ -15,4 +17,18 @@ export class TwakeCloudApi implements ICredentialType { default: '', }, ]; + authenticate = { + type: 'bearer', + properties: { + tokenPropertyName: 'workspaceKey', + }, + } as IAuthenticateBearer; + + test: ICredentialTestRequest = { + request: { + baseURL: 'https://plugins.twake.app/plugins/n8n', + url: '/channel', + method: 'POST', + }, + }; } diff --git a/packages/nodes-base/nodes/Twake/GenericFunctions.ts b/packages/nodes-base/nodes/Twake/GenericFunctions.ts index c02f3f0a0..66b182e6f 100644 --- a/packages/nodes-base/nodes/Twake/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Twake/GenericFunctions.ts @@ -28,15 +28,12 @@ export async function twakeApiRequest(this: IHookFunctions | IExecuteFunctions | method, body, qs: query, - uri: uri || `https://connectors.albatros.twakeapp.com/n8n${resource}`, + uri: uri || `https://plugins.twake.app/plugins/n8n${resource}`, json: true, }; // if (authenticationMethod === 'cloud') { - const credentials = await this.getCredentials('twakeCloudApi'); - options.headers!.Authorization = `Bearer ${credentials.workspaceKey}`; - // } else { // const credentials = await this.getCredentials('twakeServerApi'); // options.auth = { user: credentials!.publicId as string, pass: credentials!.privateApiKey as string }; @@ -44,9 +41,9 @@ export async function twakeApiRequest(this: IHookFunctions | IExecuteFunctions | // } try { - return await this.helpers.request!(options); + return await this.helpers.requestWithAuthentication.call(this, 'twakeCloudApi', options); } catch (error) { - if (error.error.code === 'ECONNREFUSED') { + if (error.error?.code === 'ECONNREFUSED') { throw new NodeApiError(this.getNode(), error, { message: 'Twake host is not accessible!' }); } throw new NodeApiError(this.getNode(), error); diff --git a/packages/nodes-base/nodes/Twake/twake.png b/packages/nodes-base/nodes/Twake/twake.png index 6bc695371..3afce345b 100644 Binary files a/packages/nodes-base/nodes/Twake/twake.png and b/packages/nodes-base/nodes/Twake/twake.png differ