Code node not working on N8N cloud

Hey, I am running a simple http request via code node in n8n but its not working, the same code node is working on another n8n instance but in my current instance its not working

N8N cloud I am using
Version: 1.72.1

const items = [];
const apiKey = 'API KEY'; // Replace with your actual API key
const limit = 10; // Max value allowed is 100

// Function to fetch data from the API using n8n's request helper
async function fetchData() {
  try {
    const endpoint = 'https://server.smartlead.ai/api/v1/email-accounts/';
    const queryString = `?api_key=${apiKey}&limit=${limit}`;

    const response = await this.helpers.request({
      method: 'GET',
      url: endpoint + queryString,
      headers: {
        'Content-Type': 'application/json',
      },
    });

    // Log the data for this API call
    console.log('API Call response:', response);

    return response; // Assuming the response is an array of objects
  } catch (error) {
    console.log('Error encountered during fetch:', error.message);
    return []; // Return an empty array in case of an error
  }
}

// Fetch the data and log the result
const response = await fetchData();
console.log('Fetched items:', response);

// Return the items in the correct format for n8n
return response.map(item => ({ json: item }));

Error - It is saying fetch is not available, HTTP is not available, like how do we make a HTTP request if literally we cant use any lib? I am using the HTTP and helper lib in other cloud instance and its working fine but same code does not work on my new cloud instance.

Help!!!

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Welcome to the community @aizad_eng !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


May I ask why you use Code node instead of HTTP Request node for this task? Also, I checked your email address and couldn’t find your n8n Cloud account. What is your n8n workspace ID?

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