From 2a2b6452dc326d8979bed0cf47fc54becd746619 Mon Sep 17 00:00:00 2001 From: Jon Date: Mon, 22 May 2023 11:11:08 +0100 Subject: [PATCH] fix(ERPNext Node): Fix issue with credential test and add frappe cloud url (#6283) --- .../credentials/ERPNextApi.credentials.ts | 36 +++++++++++++++++-- .../nodes/ERPNext/GenericFunctions.ts | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/packages/nodes-base/credentials/ERPNextApi.credentials.ts b/packages/nodes-base/credentials/ERPNextApi.credentials.ts index 0824533a86e0d..6f5686c1b4d04 100644 --- a/packages/nodes-base/credentials/ERPNextApi.credentials.ts +++ b/packages/nodes-base/credentials/ERPNextApi.credentials.ts @@ -56,6 +56,28 @@ export class ERPNextApi implements ICredentialType { }, }, }, + { + displayName: 'Domain', + name: 'domain', + type: 'options', + default: 'erpnext.com', + options: [ + { + name: 'erpnext.com', + value: 'erpnext.com', + }, + { + name: 'frappe.cloud', + value: 'frappe.cloud', + }, + ], + description: 'Domain for your cloud hosted ERPNext instance.', + displayOptions: { + show: { + environment: ['cloudHosted'], + }, + }, + }, { displayName: 'Domain', name: 'domain', @@ -90,9 +112,19 @@ export class ERPNextApi implements ICredentialType { test: ICredentialTestRequest = { request: { baseURL: - '={{$credentials.environment === "cloudHosted" ? "https://" + $credentials.subdomain + ".erpnext.com" : $credentials.domain}}', - url: '/api/resource/Doctype', + '={{$credentials.environment === "cloudHosted" ? "https://" + $credentials.subdomain + "." + $credentials.domain : $credentials.domain}}', + url: '/api/method/frappe.auth.get_logged_user', skipSslCertificateValidation: '={{ $credentials.allowUnauthorizedCerts }}', }, + rules: [ + { + type: 'responseSuccessBody', + properties: { + key: 'message', + value: undefined, + message: 'Unable to authenticate, Check the credentials and the url', + }, + }, + ], }; } diff --git a/packages/nodes-base/nodes/ERPNext/GenericFunctions.ts b/packages/nodes-base/nodes/ERPNext/GenericFunctions.ts index bb390bb26e03c..8f6f5aeda027d 100644 --- a/packages/nodes-base/nodes/ERPNext/GenericFunctions.ts +++ b/packages/nodes-base/nodes/ERPNext/GenericFunctions.ts @@ -13,7 +13,7 @@ import { NodeApiError } from 'n8n-workflow'; * Return the base API URL based on the user's environment. */ const getBaseUrl = ({ environment, domain, subdomain }: ERPNextApiCredentials) => - environment === 'cloudHosted' ? `https://${subdomain}.erpnext.com` : domain; + environment === 'cloudHosted' ? `https://${subdomain}.${domain}` : domain; export async function erpNextApiRequest( this: IExecuteFunctions | IWebhookFunctions | IHookFunctions | ILoadOptionsFunctions,