const apiFeedUrl = 'https://jsonplaceholder.typicode.com/posts'; // Replace with your actual feed URL var output = context.OutputWriter.create('JSON', { RootObj: 'results' }); const fetchData = async () => { try { // Use console.log with structured logging format for it to show up in the UI logs with the correct log level and timestamp // Using console.log with unstructured logging format will show up in the UI logs with log level MISC (miscellaneous) //This will show up in the UI logs with log level INFO and the current timestamp console.log(`${new Date()}::INFO:: Starting to fetch data from API...`); // Call the API using fetch and wait for the response const response = await fetch(apiFeedUrl); //This will show up in the UI logs with log level MISC console.log("API called"); // Check if the request was successful if (!response.ok) { //This will show up in the UI logs with log level ERROR and the current timestamp console.log(`${new Date()}::ERROR:: Failed to fetch data from API. Status: ${response.status}`); } // Parse the response as JSON and wait for it to be ready const data = await response.json(); // Write to output writer data.forEach((item) => { output.writeItem(item); }); callback(null, { previousruncontext: "This is PreviousRunContext" }); } catch (error) { // Use of console.error with structured/unstructured logging format will show up in the UI logs with the log level as ERROR console.error(`${new Date()}::ERROR:: Failed to fetch data from API: ${error.message}`); } }; // Call the fetchData function fetchData();