2023-01-27 03:22:44 -08:00
|
|
|
import type { IExecuteFunctions, IHookFunctions } from 'n8n-core';
|
2019-12-13 03:29:33 -08:00
|
|
|
|
2023-01-27 03:22:44 -08:00
|
|
|
import type { IDataObject } from 'n8n-workflow';
|
|
|
|
import { NodeApiError } from 'n8n-workflow';
|
2019-12-13 03:29:33 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Make an API request to MSG91
|
|
|
|
*
|
|
|
|
*/
|
2022-08-17 08:50:24 -07:00
|
|
|
export async function msg91ApiRequest(
|
|
|
|
this: IHookFunctions | IExecuteFunctions,
|
|
|
|
method: string,
|
|
|
|
endpoint: string,
|
|
|
|
body: IDataObject,
|
|
|
|
query?: IDataObject,
|
|
|
|
): Promise<any> {
|
2021-08-20 09:57:30 -07:00
|
|
|
const credentials = await this.getCredentials('msg91Api');
|
2019-12-13 03:29:33 -08:00
|
|
|
|
|
|
|
if (query === undefined) {
|
|
|
|
query = {};
|
2019-12-20 14:35:00 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
query.authkey = credentials.authkey as string;
|
2019-12-13 03:29:33 -08:00
|
|
|
|
|
|
|
const options = {
|
|
|
|
method,
|
|
|
|
form: body,
|
|
|
|
qs: query,
|
2019-12-20 14:35:00 -08:00
|
|
|
uri: `https://api.msg91.com/api${endpoint}`,
|
2020-10-22 06:46:03 -07:00
|
|
|
json: true,
|
2019-12-13 03:29:33 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
return await this.helpers.request(options);
|
|
|
|
} catch (error) {
|
2021-04-16 09:33:36 -07:00
|
|
|
throw new NodeApiError(this.getNode(), error);
|
2019-12-13 03:29:33 -08:00
|
|
|
}
|
2019-12-20 14:35:00 -08:00
|
|
|
}
|