mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-16 09:34:07 -08:00
91d7e16c81
* 🔨 formatting nodes with prettier
48 lines
1 KiB
TypeScript
48 lines
1 KiB
TypeScript
import { IExecuteFunctions, IHookFunctions } from 'n8n-core';
|
|
|
|
import { IDataObject, ILoadOptionsFunctions, NodeApiError } from 'n8n-workflow';
|
|
|
|
import { OptionsWithUri } from 'request';
|
|
|
|
/**
|
|
* Make an authenticated API request to Raindrop.
|
|
*/
|
|
export async function raindropApiRequest(
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
|
method: string,
|
|
endpoint: string,
|
|
qs: IDataObject,
|
|
body: IDataObject,
|
|
option: IDataObject = {},
|
|
) {
|
|
const options: OptionsWithUri = {
|
|
headers: {
|
|
'user-agent': 'n8n',
|
|
'Content-Type': 'application/json',
|
|
},
|
|
method,
|
|
uri: `https://api.raindrop.io/rest/v1${endpoint}`,
|
|
qs,
|
|
body,
|
|
json: true,
|
|
};
|
|
|
|
if (!Object.keys(body).length) {
|
|
delete options.body;
|
|
}
|
|
|
|
if (!Object.keys(qs).length) {
|
|
delete options.qs;
|
|
}
|
|
|
|
if (Object.keys(option).length !== 0) {
|
|
Object.assign(options, option);
|
|
}
|
|
|
|
try {
|
|
return await this.helpers.requestOAuth2!.call(this, 'raindropOAuth2Api', options);
|
|
} catch (error) {
|
|
throw new NodeApiError(this.getNode(), error);
|
|
}
|
|
}
|