2022-08-17 08:50:24 -07:00
|
|
|
import { IExecuteFunctions, IHookFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
2020-08-04 08:30:08 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { OptionsWithUri } from 'request';
|
2020-08-04 08:30:08 -07:00
|
|
|
|
2020-08-04 08:23:06 -07:00
|
|
|
/**
|
|
|
|
* Make an API request to Twake
|
|
|
|
*
|
|
|
|
*/
|
2022-08-17 08:50:24 -07:00
|
|
|
export async function twakeApiRequest(
|
|
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
|
|
|
method: string,
|
|
|
|
resource: string,
|
|
|
|
body: object,
|
|
|
|
query?: object,
|
|
|
|
uri?: string,
|
2022-11-08 06:28:21 -08:00
|
|
|
) {
|
2020-08-04 08:23:06 -07:00
|
|
|
const options: OptionsWithUri = {
|
|
|
|
headers: {},
|
|
|
|
method,
|
|
|
|
body,
|
|
|
|
qs: query,
|
2023-01-13 09:11:56 -08:00
|
|
|
uri: uri ?? `https://plugins.twake.app/plugins/n8n${resource}`,
|
2020-08-04 08:23:06 -07:00
|
|
|
json: true,
|
|
|
|
};
|
|
|
|
|
2020-08-04 08:30:08 -07:00
|
|
|
// if (authenticationMethod === 'cloud') {
|
|
|
|
// } else {
|
2021-08-20 09:57:30 -07:00
|
|
|
// const credentials = await this.getCredentials('twakeServerApi');
|
2020-08-04 08:30:08 -07:00
|
|
|
// options.auth = { user: credentials!.publicId as string, pass: credentials!.privateApiKey as string };
|
|
|
|
// options.uri = `${credentials!.hostUrl}/api/v1${resource}`;
|
|
|
|
// }
|
2020-08-04 08:23:06 -07:00
|
|
|
|
2022-11-22 08:57:17 -08:00
|
|
|
return this.helpers.requestWithAuthentication.call(this, 'twakeCloudApi', options);
|
2020-08-04 08:23:06 -07:00
|
|
|
}
|