mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-30 06:59:41 -08:00
0ecbb4a19d
* 🔨 prettier formated nodes - A * 🔨 prettier formated nodes - B * ⚡ prettier formated nodes - C * ⚡ prettier formated nodes - D * ⚡ prettier formated nodes - E-F * 🎨 Adjust nodes-base formatting command (#3805) * Format additional files in nodes A-F (#3811) * ⚡ fixes * 🎨 Add Mindee to ignored dirs Co-authored-by: Iván Ovejero <ivov.src@gmail.com>
80 lines
1.6 KiB
TypeScript
80 lines
1.6 KiB
TypeScript
import { IExecuteFunctions, IHookFunctions } from 'n8n-core';
|
|
|
|
import {
|
|
ICredentialDataDecryptedObject,
|
|
ICredentialTestFunctions,
|
|
IDataObject,
|
|
ILoadOptionsFunctions,
|
|
NodeApiError,
|
|
} from 'n8n-workflow';
|
|
|
|
import { OptionsWithUri } from 'request';
|
|
|
|
/**
|
|
* Make an authenticated API request to Bubble.
|
|
*/
|
|
export async function dropcontactApiRequest(
|
|
this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions,
|
|
method: string,
|
|
endpoint: string,
|
|
body: IDataObject,
|
|
qs: IDataObject,
|
|
) {
|
|
const { apiKey } = (await this.getCredentials('dropcontactApi')) as {
|
|
apiKey: string;
|
|
};
|
|
|
|
const options: OptionsWithUri = {
|
|
headers: {
|
|
'user-agent': 'n8n',
|
|
'X-Access-Token': apiKey,
|
|
},
|
|
method,
|
|
uri: `https://api.dropcontact.io${endpoint}`,
|
|
qs,
|
|
body,
|
|
json: true,
|
|
};
|
|
|
|
if (!Object.keys(body).length) {
|
|
delete options.body;
|
|
}
|
|
|
|
if (!Object.keys(qs).length) {
|
|
delete options.qs;
|
|
}
|
|
|
|
try {
|
|
return await this.helpers.request!(options);
|
|
} catch (error) {
|
|
throw new NodeApiError(this.getNode(), error);
|
|
}
|
|
}
|
|
|
|
export async function validateCredentials(
|
|
this: ICredentialTestFunctions,
|
|
decryptedCredentials: ICredentialDataDecryptedObject,
|
|
// tslint:disable-next-line:no-any
|
|
): Promise<any> {
|
|
const credentials = decryptedCredentials;
|
|
|
|
const { apiKey } = credentials as {
|
|
apiKey: string;
|
|
};
|
|
|
|
const options: OptionsWithUri = {
|
|
headers: {
|
|
'user-agent': 'n8n',
|
|
'X-Access-Token': apiKey,
|
|
},
|
|
method: 'POST',
|
|
body: {
|
|
data: [{ email: '' }],
|
|
},
|
|
uri: `https://api.dropcontact.io/batch`,
|
|
json: true,
|
|
};
|
|
|
|
return this.helpers.request!(options);
|
|
}
|