HTTP call in function node

Hi,
I am doing HTTP requests in the function node as I need to filter the responses directly in the node.

I make 200 http calls. However, I get the following error after some time:

TypeError: Cannot read properties of undefined (reading 'split')
    at Object.execute (/usr/local/lib/node_modules/n8n/node_modules/n8n-nodes-base/dist/nodes/Function/Function.node.js:127:91)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /usr/local/lib/node_modules/n8n/node_modules/n8n-core/dist/src/WorkflowExecute.js:451:47

I checked the source code but not really sure what is going on.

You should be able to reproduce the error with the following workflow:

Hi @Ak92, welcome to the community!

That’s a lot of custom code you’re running there and I am not sure I fully understand it. I was also not able to test this as the server closed the connection when I tried calling the first URL generated. Form the looks of it you’re fetching a HTML page and are then extracting individual values from it.

Have you checked out the HTTP Request and HTML Extract nodes? These are purpose built and might make things easier.

Edit: Looks like the server is working now, here is a quick example workflow showing what I mean (it currently only extracts the company name after e-Äriregister –, but you can of course adjust the flow as needed).

On a side note, this workflow seems to require a lot of memory due to the HTTP Request response size. So you might want to consider splitting it in a parent workflow (providing the URLs and splitting the data into smaller batches) and a sub-workflow only returning the actually required data. Like so:

Parent:

Sub:

Thank you!
Yes that is correct. I am doing this as HTML pages returned by some URLs are huge. Using the HTTP node and then extracting the data results in the workflow failing (lost connection). For this reason I need to extract the data in the Function node.

I just found a quick fix by first sending a HEAD request with the HTTP node so that I can filter for the pages I exactly want.
I will check the batch option as well in case of future errors
Thank you!

1 Like

Sweet, glad to hear this was already useful! Thanks so much for confirming :slight_smile: