Hi everyone, I’m running into an issue in the Code node when trying to call an external API. I’m getting an error:
fetch is not defined
My workflow is:
HTTP Request → Code → Next Node
Inside the Code node, I’m trying to make another API call like this:
const res = await fetch(‘https://api.example.com/data’);
const data = await res.json();
return [
{
json: data
}
];
But it throws the error and doesn’t execute.
I thought fetch would work inside the Code node, but maybe I’m missing something about the environment n8n uses.
Describe the problem/error/question
What’s the correct way to make external API calls inside an n8n Code node? Or should I be using a different node for this?
What is the error message (if any)?
Please share your workflow
(Select the nodes on your canvas and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow.)
Share the output returned by the last node
Information on your n8n setup
- n8n version:
- Database (default: SQLite):
- n8n EXECUTIONS_PROCESS setting (default: own, main):
- Running n8n via (Docker, npm, n8n cloud, desktop app):
- Operating system: