2023-01-27 03:22:44 -08:00
|
|
|
import type { OptionsWithUri } from 'request';
|
2023-03-09 09:13:15 -08:00
|
|
|
import type { IExecuteFunctions, IHookFunctions, ILoadOptionsFunctions } from 'n8n-workflow';
|
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-19 04:37:19 -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
|
|
|
|
2024-01-17 07:08:50 -08:00
|
|
|
return await this.helpers.requestWithAuthentication.call(this, 'twakeCloudApi', options);
|
2020-08-04 08:23:06 -07:00
|
|
|
}
|