Make the base URL of a node configurable (Custom node)

Is there a way to make the base URL of the API a node is calling configurable, when building a custom node?

My first intuition would be to add a parameter for this but then the user would need to set this with every request which might get cumbersome fast. Maybe this could be configured with the credentials?

Hey @kolaente,

We normally do this in the credential, If you check one of the existing nodes like Wordpress you can see how we do this. If you are using the declarative style you can see how I normally handle this in a community node I created here: GitHub - Joffcom/n8n-nodes-plausible: n8n community node for Plausible

Awesome, that works!

Do you also happen to know how I can use this in a search method of a resource locator?

I’ve tried using it like this:

const baseUrl = '={{$credentials.apiUrl.replace(new RegExp("/$"), "")}}'

const options: OptionsWithUri = {
	method: 'GET',
	uri: `${baseUrl}/projects`,
	json: true,
}

but the template expression is not resolved.

Figured it out:

const credentialType = 'apiCredentials'
const cred = await this.getCredentials(credentialType)

const options: OptionsWithUri = {
	method: 'GET',
	uri: `${cred.apiUrl}/projects`,
	json: true,
}
2 Likes

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