2024-02-14 07:29:09 -08:00
|
|
|
import type {
|
|
|
|
IDataObject,
|
|
|
|
IExecuteFunctions,
|
|
|
|
IHookFunctions,
|
|
|
|
IHttpRequestMethods,
|
|
|
|
ILoadOptionsFunctions,
|
|
|
|
IRequestOptions,
|
|
|
|
} 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,
|
2024-02-14 07:29:09 -08:00
|
|
|
method: IHttpRequestMethods,
|
2022-08-17 08:50:24 -07:00
|
|
|
resource: string,
|
|
|
|
body: object,
|
2024-02-14 07:29:09 -08:00
|
|
|
query?: IDataObject,
|
2022-08-17 08:50:24 -07:00
|
|
|
uri?: string,
|
2022-11-08 06:28:21 -08:00
|
|
|
) {
|
2024-02-14 07:29:09 -08:00
|
|
|
const options: IRequestOptions = {
|
2020-08-04 08:23:06 -07:00
|
|
|
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
|
|
|
}
|