From a885518019bc8cb477150a2ec40ef1f7b2e8e956 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ovejero?= Date: Fri, 7 May 2021 10:02:53 +0200 Subject: [PATCH] :zap: Refactor out extra credentials parameter --- .../credentials/ZohoOAuth2Api.credentials.ts | 18 +----------------- .../nodes-base/nodes/Zoho/GenericFunctions.ts | 11 +++-------- 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/packages/nodes-base/credentials/ZohoOAuth2Api.credentials.ts b/packages/nodes-base/credentials/ZohoOAuth2Api.credentials.ts index b2c8f44b16..d9fedc56fe 100644 --- a/packages/nodes-base/credentials/ZohoOAuth2Api.credentials.ts +++ b/packages/nodes-base/credentials/ZohoOAuth2Api.credentials.ts @@ -53,28 +53,12 @@ export class ZohoOAuth2Api implements ICredentialType { }, { name: 'CN - https://accounts.zoho.com.cn/oauth/v2/token', - value: ' https://accounts.zoho.com.cn/oauth/v2/token', + value: 'https://accounts.zoho.com.cn/oauth/v2/token', }, ], default: 'https://accounts.zoho.com/oauth/v2/token', required: true, }, - { - displayName: 'Region', - name: 'region', - type: 'options' as NodePropertyTypes, - default: 'europe', - options: [ - { - name: 'Europe', - value: 'europe', - }, - { - name: 'United States', - value: 'unitedStates', - }, - ], - }, { displayName: 'Scope', name: 'scope', diff --git a/packages/nodes-base/nodes/Zoho/GenericFunctions.ts b/packages/nodes-base/nodes/Zoho/GenericFunctions.ts index 882b009fef..0e2ec8b1b3 100644 --- a/packages/nodes-base/nodes/Zoho/GenericFunctions.ts +++ b/packages/nodes-base/nodes/Zoho/GenericFunctions.ts @@ -6,7 +6,6 @@ import { import { IDataObject, NodeApiError, - NodeOperationError, } from 'n8n-workflow'; import { @@ -27,8 +26,7 @@ export async function zohoApiRequest( ) { const operation = this.getNodeParameter('operation', 0) as string; - const { region } = this.getCredentials('zohoOAuth2Api') as { region: 'europe' | 'unitedStates' }; - const tld = getTld(region); + const { oauthTokenData: { api_domain: apiDomain } } = this.getCredentials('zohoOAuth2Api') as { oauthTokenData: { api_domain: string} }; const options: OptionsWithUri = { body: { @@ -38,7 +36,7 @@ export async function zohoApiRequest( }, method, qs, - uri: uri ?? `https://www.zohoapis.${tld}/crm/v2${endpoint}`, + uri: uri ?? `${apiDomain}/crm/v2${endpoint}`, json: true, }; @@ -51,7 +49,7 @@ export async function zohoApiRequest( } try { - console.log(JSON.stringify(options.body.data, null, 2)); + console.log(JSON.stringify(options, null, 2)); const responseData = await this.helpers.requestOAuth2.call(this, 'zohoOAuth2Api', options); return operation === 'getAll' ? responseData : responseData.data; } catch (error) { @@ -151,9 +149,6 @@ function hasAddressFields(locationField: unknown): locationField is LocationFiel return locationField.hasOwnProperty('address_fields'); } -const getTld = (region: 'europe' | 'unitedStates') => - ({ europe: 'eu', unitedStates: 'com' }[region]); - // ---------------------------------------- // types // ----------------------------------------