[BUG] Can't use `credentialTest` method in custom node

[BUG] credentialTest Method Not Used in Custom Node

Description

The credentialTest method defined in a custom n8n node is not being used when the node is installed inside ~/.n8n/custom. However, the method works correctly in the official Odoo node.

Steps to Reproduce

  1. Start from the n8n-node-starter template.
  2. Copy the Odoo node from the official n8n repo and modify it to create a custom node with its own credential type.
  3. Install the custom node inside ~/.n8n/custom.
  4. Attempt to use the credentialTest method.

Expected Behavior

The credentialTest method should be executed when testing credentials, just like in the official Odoo node.

Actual Behavior

The credentialTest method is not called when using the custom node installed in ~/.n8n/custom.

Additional Context

Attempted Solutions

  1. Added "n8n-core" as a devDependency.
  2. Updated the build script from:
    tsc && gulp build:icons
    
    to:
    tsc && gulp build:icons && pnpm n8n-generate-metadata
    
  3. This added known, methods, and types folders to the dist output, but the credentialTest method still isn’t executed.

Environment

  • n8n Version: 1.81.4
  • Node.js Version: v22.14.0
  • Operating System: WSL Ubuntu LTS
  • Installation Method: Custom node linked from ~/.n8n/custom, n8n built and executed from source using pnpm start with pnpm dev launched after a pnpm build in the custom node directory

Would appreciate any insights on why the method isn’t triggered in custom nodes!

Yeah, this is a known issue with custom nodes placed in ~/.n8n/custom the credentialTest method doesn’t get triggered from there, even if it’s defined correctly.

What’s happening:
n8n doesn’t register the credentialTest function unless the node is fully packaged and loaded like an official community node (with proper metadata and published structure). The local ~/.n8n/custom path often skips this metadata link.

Quick workaround:
Instead of linking manually to ~/.n8n/custom, try this:

Inside your custom node folder, make sure you’ve generated the metadata:

pnpm n8n-generate-metadata

Then install your node as a local package, not just symlink:

cd your-node-folder
npm pack

Install it in your main n8n project:

npm install /path/to/your-node.tgz

That way, n8n loads your node just like a real package and picks up the credentialTest method properly.

Alternative:
You can also publish it to a private NPM registry (or GitHub) and install from there that also works fine with credentialTest.

Let me know if you want a basic example structure to test this setup.

Hey there, thanks for your input.

This would indeed seem like a great solution. The issue is how to manage the development environment properly to avoid needing all these install steps while iterating.

Another workaround I used is this one in the CustomOdooApi.credentials.ts :

export class CustomOdooApi implements ICredentialType {
test: ICredentialTestRequest = {
		// TODO: Remove when the `credentialTest` test from CustomOdoo.node.ts is fixed
		request: {
			baseURL: '={{$credentials.url}}',
			url: '/jsonrpc',
			method: 'POST',
			body: {
				jsonrpc: '2.0',
				method: 'call',
				params: {
					service: 'common',
					method: 'login',
					args: [
						'={{$credentials.db}}',
						'={{$credentials.username}}',
						'={{$credentials.password}}',
					],
				},
				id: randomInt(100),
			},
		},
		rules: [
			{
				type: 'responseSuccessBody',
				properties: {
					key: 'result',
					value: (val: any) => typeof val === 'number',
					message: 'The Odoo API credentials are valid!',
				},
			},
			{
				type: 'responseSuccessBody',
				properties: {
					key: 'result',
					value: false,
					message: 'The Odoo API credentials are not valid!',
				},
			},
			{
				type: 'responseSuccessBody',
				properties: {
					key: 'error.message',
					value: 'Odoo Server Error',
					message: 'Odoo Server Error, check the server logs for more details.',
				},
			},
		],
	};
}

Nice! Glad you found a workaround. Your approach using test.request directly in credentials.ts definitely has its upsides — it works without needing the credentialTest() in the node itself and gives you immediate control over the response, especially during development.

The good part is you avoid messing with the node core and can test based on a direct API response.
The tradeoff is that depending on the API, this can make your credentials.ts a bit more rigid or harder to reuse across other nodes.

If you want to keep the test lighter and more flexible, you could simplify it by just doing a GET on a basic endpoint like /ping, /health, or something similar — just enough to check the connection and get a 200 response. That way your test loop stays clean and quick without depending on JSON-RPC or multiple rules.

If you want an example of this lighter version, just let me know and I’ll send it your way!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.