2023-01-27 03:22:44 -08:00
|
|
|
import type { IExecuteFunctions } from 'n8n-core';
|
2020-06-23 08:18:01 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { IDataObject } from 'n8n-workflow';
|
|
|
|
import { NodeApiError } from 'n8n-workflow';
|
2020-06-23 08:18:01 -07:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { OptionsWithUri } from 'request';
|
2021-01-31 11:07:32 -08:00
|
|
|
|
2020-06-23 08:18:01 -07:00
|
|
|
/**
|
2020-06-24 21:06:48 -07:00
|
|
|
* Make an API request to SIGNL4
|
2020-06-23 08:18:01 -07:00
|
|
|
*
|
|
|
|
* @param {IHookFunctions | IExecuteFunctions} this
|
2021-01-31 11:07:32 -08:00
|
|
|
*
|
2020-06-23 08:18:01 -07:00
|
|
|
*/
|
|
|
|
|
2022-08-17 08:50:24 -07:00
|
|
|
export async function SIGNL4ApiRequest(
|
|
|
|
this: IExecuteFunctions,
|
|
|
|
method: string,
|
|
|
|
body: string,
|
|
|
|
query: IDataObject = {},
|
|
|
|
option: IDataObject = {},
|
|
|
|
): Promise<any> {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('signl4Api');
|
2021-01-28 21:46:28 -08:00
|
|
|
|
|
|
|
const teamSecret = credentials?.teamSecret as string;
|
2020-06-24 21:06:48 -07:00
|
|
|
|
|
|
|
let options: OptionsWithUri = {
|
|
|
|
headers: {
|
2022-08-17 08:50:24 -07:00
|
|
|
Accept: '*/*',
|
2020-06-24 21:06:48 -07:00
|
|
|
},
|
|
|
|
method,
|
|
|
|
body,
|
|
|
|
qs: query,
|
2021-01-28 21:46:28 -08:00
|
|
|
uri: `https://connect.signl4.com/webhook/${teamSecret}`,
|
|
|
|
json: true,
|
2020-06-24 21:06:48 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
if (!Object.keys(body).length) {
|
|
|
|
delete options.body;
|
2020-06-23 08:18:01 -07:00
|
|
|
}
|
2020-06-24 21:06:48 -07:00
|
|
|
if (!Object.keys(query).length) {
|
|
|
|
delete options.qs;
|
2020-06-23 08:18:01 -07:00
|
|
|
}
|
2020-06-24 21:06:48 -07:00
|
|
|
options = Object.assign({}, options, option);
|
2020-06-23 08:18:01 -07:00
|
|
|
|
2020-06-24 21:06:48 -07:00
|
|
|
try {
|
2022-12-02 12:54:28 -08:00
|
|
|
return await this.helpers.request(options);
|
2020-06-24 21:06:48 -07:00
|
|
|
} catch (error) {
|
2021-04-16 09:33:36 -07:00
|
|
|
throw new NodeApiError(this.getNode(), error);
|
2020-06-23 08:18:01 -07:00
|
|
|
}
|
|
|
|
}
|