n8n/packages/nodes-base/nodes/Msg91/GenericFunctions.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
781 B
TypeScript
Raw Normal View History

import type { IExecuteFunctions, IHookFunctions, IDataObject, JsonObject } from 'n8n-workflow';
import { NodeApiError } from 'n8n-workflow';
2019-12-13 03:29:33 -08:00
/**
* Make an API request to MSG91
*
*/
export async function msg91ApiRequest(
this: IHookFunctions | IExecuteFunctions,
method: string,
endpoint: string,
body: IDataObject,
query?: IDataObject,
): Promise<any> {
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) {
throw new NodeApiError(this.getNode(), error as JsonObject);
2019-12-13 03:29:33 -08:00
}
2019-12-20 14:35:00 -08:00
}