mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
Merge branch 'Master' into 'Pipedrive-OAuth2-support'
This commit is contained in:
@@ -5,10 +5,16 @@ import {
|
||||
|
||||
import {
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { OptionsWithUri } from 'request';
|
||||
import {
|
||||
OptionsWithUri,
|
||||
} from 'request';
|
||||
<<<<<<< HEAD
|
||||
|
||||
=======
|
||||
>>>>>>> master
|
||||
|
||||
export interface ICustomInterface {
|
||||
name: string;
|
||||
@@ -32,10 +38,27 @@ export interface ICustomProperties {
|
||||
* @param {object} body
|
||||
* @returns {Promise<any>}
|
||||
*/
|
||||
<<<<<<< HEAD
|
||||
export async function pipedriveApiRequest(this: IHookFunctions | IExecuteFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, formData?: IDataObject, downloadFile?: boolean): Promise<any> { // tslint:disable-line:no-any
|
||||
const authenticationMethod = this.getNodeParameter('authentication', 0);
|
||||
=======
|
||||
export async function pipedriveApiRequest(this: IHookFunctions | IExecuteFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: IDataObject, query?: IDataObject, formData?: IDataObject, downloadFile?: boolean): Promise<any> { // tslint:disable-line:no-any
|
||||
const credentials = this.getCredentials('pipedriveApi');
|
||||
if (credentials === undefined) {
|
||||
throw new Error('No credentials got returned!');
|
||||
}
|
||||
|
||||
if (query === undefined) {
|
||||
query = {};
|
||||
}
|
||||
|
||||
query.api_token = credentials.apiToken;
|
||||
>>>>>>> master
|
||||
|
||||
const options: OptionsWithUri = {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
},
|
||||
method,
|
||||
qs: query,
|
||||
uri: `https://api.pipedrive.com/v1${endpoint}`,
|
||||
@@ -62,7 +85,8 @@ export async function pipedriveApiRequest(this: IHookFunctions | IExecuteFunctio
|
||||
let responseData;
|
||||
|
||||
try {
|
||||
if (authenticationMethod === 'basicAuth') {
|
||||
<<<<<<< HEAD
|
||||
if (authenticationMethod === 'basicAuth' || authenticationMethod === 'apiToken') {
|
||||
|
||||
const credentials = this.getCredentials('pipedriveApi');
|
||||
if (credentials === undefined) {
|
||||
@@ -76,6 +100,10 @@ export async function pipedriveApiRequest(this: IHookFunctions | IExecuteFunctio
|
||||
} else {
|
||||
responseData = await this.helpers.requestOAuth2!.call(this, 'pipedriveOAuth2Api', options);
|
||||
}
|
||||
=======
|
||||
//@ts-ignore
|
||||
const responseData = await this.helpers.request(options);
|
||||
>>>>>>> master
|
||||
|
||||
if (downloadFile === true) {
|
||||
return {
|
||||
@@ -99,7 +127,7 @@ export async function pipedriveApiRequest(this: IHookFunctions | IExecuteFunctio
|
||||
|
||||
if (error.response && error.response.body && error.response.body.error) {
|
||||
// Try to return the error prettier
|
||||
let errorMessage = `Pipedrive error response [${error.statusCode}]: ${error.response.body.error}`;
|
||||
let errorMessage = `Pipedrive error response [${error.statusCode}]: ${error.response.body.error.message}`;
|
||||
if (error.response.body.error_info) {
|
||||
errorMessage += ` - ${error.response.body.error_info}`;
|
||||
}
|
||||
@@ -128,7 +156,7 @@ export async function pipedriveApiRequestAllItems(this: IHookFunctions | IExecut
|
||||
if (query === undefined) {
|
||||
query = {};
|
||||
}
|
||||
query.limit = 500;
|
||||
query.limit = 100;
|
||||
query.start = 0;
|
||||
|
||||
const returnData: IDataObject[] = [];
|
||||
@@ -137,7 +165,12 @@ export async function pipedriveApiRequestAllItems(this: IHookFunctions | IExecut
|
||||
|
||||
do {
|
||||
responseData = await pipedriveApiRequest.call(this, method, endpoint, body, query);
|
||||
returnData.push.apply(returnData, responseData.data);
|
||||
// the search path returns data diferently
|
||||
if (responseData.data.items) {
|
||||
returnData.push.apply(returnData, responseData.data.items);
|
||||
} else {
|
||||
returnData.push.apply(returnData, responseData.data);
|
||||
}
|
||||
|
||||
query.start = responseData.additionalData.pagination.next_start;
|
||||
} while (
|
||||
|
||||
Reference in New Issue
Block a user