2022-09-30 04:16:59 -07:00
|
|
|
import { IExecuteFunctions, IHookFunctions, ILoadOptionsFunctions } from 'n8n-core';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
import { OptionsWithUri } from 'request';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-11-11 07:07:50 -08:00
|
|
|
import { IDataObject } from 'n8n-workflow';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
export async function apiRequest(
|
|
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
|
|
|
method: string,
|
|
|
|
endpoint: string,
|
|
|
|
body: object,
|
|
|
|
query?: IDataObject,
|
|
|
|
// tslint:disable-next-line:no-any
|
|
|
|
): Promise<any> {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('wekanApi');
|
2020-10-13 04:00:14 -07:00
|
|
|
|
|
|
|
query = query || {};
|
|
|
|
|
|
|
|
const options: OptionsWithUri = {
|
|
|
|
headers: {
|
2022-08-17 08:50:24 -07:00
|
|
|
Accept: 'application/json',
|
2020-10-13 04:00:14 -07:00
|
|
|
},
|
|
|
|
method,
|
|
|
|
body,
|
|
|
|
qs: query,
|
|
|
|
uri: `${credentials.url}/api/${endpoint}`,
|
|
|
|
json: true,
|
|
|
|
};
|
|
|
|
|
2022-11-11 02:32:43 -08:00
|
|
|
return await this.helpers.requestWithAuthentication.call(this, 'wekanApi', options);
|
2020-10-13 04:00:14 -07:00
|
|
|
}
|