From aca8441164d6a9f644dd8280df2a04c24eaf6f76 Mon Sep 17 00:00:00 2001 From: Rupenieks Date: Sat, 2 May 2020 13:59:17 +0200 Subject: [PATCH] Fixed GET method 400 response --- packages/nodes-base/nodes/AgileCrm/AgileCrm.node.ts | 6 +++--- .../nodes-base/nodes/AgileCrm/GenericFunctions.ts | 13 ++++++++----- packages/nodes-base/package.json | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/nodes-base/nodes/AgileCrm/AgileCrm.node.ts b/packages/nodes-base/nodes/AgileCrm/AgileCrm.node.ts index 84be0ddcfc..4d493bffbd 100644 --- a/packages/nodes-base/nodes/AgileCrm/AgileCrm.node.ts +++ b/packages/nodes-base/nodes/AgileCrm/AgileCrm.node.ts @@ -76,7 +76,7 @@ export class AgileCrm implements INodeType { const contactId = this.getNodeParameter('contactId', i) as string; const endpoint = `api/contacts/${contactId}`; - responseData = await agileCrmApiRequest.call(this, 'GET', endpoint); + responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {}); } @@ -85,11 +85,11 @@ export class AgileCrm implements INodeType { if (returnAll) { const endpoint = `api/contacts`; - responseData = await agileCrmApiRequest.call(this, 'GET', endpoint); + responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {}); } else { const limit = this.getNodeParameter('limit', i) as number; const endpoint = `api/contacts?page_size=${limit}`; - responseData = await agileCrmApiRequest.call(this, 'GET', endpoint); + responseData = await agileCrmApiRequest.call(this, 'GET', endpoint, {}); } } diff --git a/packages/nodes-base/nodes/AgileCrm/GenericFunctions.ts b/packages/nodes-base/nodes/AgileCrm/GenericFunctions.ts index d363443b50..cabcf2c322 100644 --- a/packages/nodes-base/nodes/AgileCrm/GenericFunctions.ts +++ b/packages/nodes-base/nodes/AgileCrm/GenericFunctions.ts @@ -14,17 +14,14 @@ import { } from 'n8n-workflow'; -export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: any = {}, query: IDataObject = {}, uri?: string): Promise { +export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions, method: string, endpoint: string, body: object, query: IDataObject = {}, uri?: string): Promise { - const node = this.getNodeParameter('credentials', 1); const credentials = this.getCredentials('agileCrmApi'); - const options: OptionsWithUri = { method, headers: { 'Accept': 'application/json', }, - body: body! || {}, auth: { username: credentials!.email as string, password: credentials!.apiKey as string @@ -32,8 +29,14 @@ export async function agileCrmApiRequest(this: IHookFunctions | IExecuteFunction uri: uri || `https://n8nio.agilecrm.com/dev/${endpoint}`, json: true }; - + // Only add Body property if method not GET to avoid 400 response + if(method !== "GET"){ + options.body = body; + } + + console.log(options); + try { return await this.helpers.request!(options); } catch (error) { diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index d147d860d0..6b8b9c9713 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -27,7 +27,7 @@ "n8n": { "credentials": [ "dist/credentials/ActiveCampaignApi.credentials.js", - "dist/credentials/AgileCrm.credentials.js", + "dist/credentials/AgileCrmApi.credentials.js", "dist/credentials/AcuitySchedulingApi.credentials.js", "dist/credentials/AirtableApi.credentials.js", "dist/credentials/Amqp.credentials.js",