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!!!