Declarative-Style Node: How to make two API requests for an operation?

Describe the problem/error/question

In order to simplify the creation of workflows for our end users I’d like to combine two API requests in a single operation. These API requests are use together very frequently.

What is the error message (if any)?

No error message but I’ve tried to find an answer in the docs, the forum and Quora but I couldn’t get the solution to make it work in a declarative-style node.

Node property

/* Browser Window Operations */
{
	displayName: 'Operation',
	name: 'operation',
	type: 'options',
	noDataExpression: true,
	displayOptions: {
		show: {
			resource: ['browserWindow'],
		},
	},
	options: [
		{
			name: 'Create',
			value: 'createBrowserWindow',
			action: 'Create browser window',
			description: 'Create a new browser window',
			routing: {
				request: {
					method: 'POST',
					url: '=/sessions/{{$parameter["sessionId"]}}/windows',
				},
				/* 
				* Here I'd like to add another request to another endpoint
				* with the value from the response of the first request
				*/

				// {
				// 	method: 'POST',
				// 	url: '=/sessions/{{$parameter["sessionId"]}}/windows/{{$response["windowId"]}}',
				// },
			},
		}
	],
},

Information on your n8n setup

  • n8n version: 1.75.0
  • Database (default: SQLite): PostgreSQL
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker (VS Code container)
  • Operating system: Mac OS Sonoma
1 Like

Hey @cesar-airtop,

I’ve heard there’s a feature in development for turning sub-workflows into Custom Nodes.

But until then, you could solve this issue by:

  1. Creating a sub-workflow
  2. Calling this sub-workflow using the Execute Workflow node

When creating the subworkflow you can define which variables it will receive as input. And then in the sub-workflow you can do your magic that the final user won’t need to see.

If my reply answers your question, please remember to mark it as a solution.

Thank you for your response @solomon. I decided to go and build a programatic-style node since we want to give to our users an out-of-the-box experience and programatic-styled nodes offer more options for building nodes that need to make HTTP requests based on conditions.

Hope this answer helps other n8n developers in the same situation.

2 Likes

That’s very interesting. Thanks for sharing your solution

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