2023-01-27 03:22:44 -08:00
|
|
|
import type { OptionsWithUri } from 'request';
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2023-03-09 09:13:15 -08:00
|
|
|
import type {
|
|
|
|
IDataObject,
|
|
|
|
IExecuteFunctions,
|
|
|
|
IHookFunctions,
|
|
|
|
ILoadOptionsFunctions,
|
|
|
|
} 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,
|
|
|
|
): Promise<any> {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('wekanApi');
|
2020-10-13 04:00:14 -07:00
|
|
|
|
2023-01-19 04:37:19 -08:00
|
|
|
query = query || {};
|
2020-10-13 04:00:14 -07:00
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2024-01-17 07:08:50 -08:00
|
|
|
return await this.helpers.requestWithAuthentication.call(this, 'wekanApi', options);
|
2020-10-13 04:00:14 -07:00
|
|
|
}
|