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

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

34 lines
792 B
TypeScript
Raw Normal View History

import type { OptionsWithUri } from 'request';
import type {
IDataObject,
2020-01-23 09:27:28 -08:00
IExecuteFunctions,
IHookFunctions,
ILoadOptionsFunctions,
IWebhookFunctions,
} from 'n8n-workflow';
2020-01-23 09:27:28 -08:00
export async function segmentApiRequest(
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions | IWebhookFunctions,
method: string,
resource: string,
body: any = {},
qs: IDataObject = {},
uri?: string,
_option: IDataObject = {},
): Promise<any> {
2020-01-23 09:27:28 -08:00
const options: OptionsWithUri = {
headers: {
'Content-Type': 'application/json',
},
method,
qs,
body,
uri: uri || `https://api.segment.io/v1${resource}`,
2020-10-22 06:46:03 -07:00
json: true,
2020-01-23 09:27:28 -08:00
};
if (!Object.keys(body as IDataObject).length) {
2020-01-23 09:27:28 -08:00
delete options.body;
}
return this.helpers.requestWithAuthentication.call(this, 'segmentApi', options);
2020-01-23 09:27:28 -08:00
}