mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
⚡ Improvements to Converkit-Node
This commit is contained in:
@@ -15,7 +15,9 @@ import {
|
||||
|
||||
export async function convertKitApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IHookFunctions,
|
||||
method: string, endpoint: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('convertKitApi');
|
||||
|
||||
const credentials = this.getCredentials('convertKitApi');
|
||||
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
@@ -30,15 +32,29 @@ export async function convertKitApiRequest(this: IExecuteFunctions | IExecuteSin
|
||||
uri: uri ||`https://api.convertkit.com/v3${endpoint}`,
|
||||
json: true,
|
||||
};
|
||||
|
||||
options = Object.assign({}, options, option);
|
||||
|
||||
if (Object.keys(options.body).length === 0) {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
console.log(options);
|
||||
|
||||
try {
|
||||
|
||||
qs.api_secret = credentials.apiSecret;
|
||||
|
||||
return await this.helpers.request!(options);
|
||||
|
||||
} catch (error) {
|
||||
throw new Error(`ConvertKit error response: ${error.message}`);
|
||||
|
||||
let errorMessage = error;
|
||||
|
||||
if (error.response && error.response.body && error.response.body.message) {
|
||||
errorMessage = error.response.body.message;
|
||||
}
|
||||
|
||||
throw new Error(`ConvertKit error response: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user