How to Link Function Node with HTTP Request in AI Agent Workflow

I’m pretty new to n8n and don’t have much coding experience, so this could be a simple issue I’m missing. I can’t figure out how to properly link a Function node to an HTTP Request node when working within an AI Agent setup.

Basically, I created an HTTP request that calls the Google Places API to fetch data about new restaurants in my area. Now I want to process this data to show only places with ratings above 4 stars and limit the output to just the first 10 results. Everything I’ve read suggests connecting the HTTP request to a function node for data processing, but I’m having trouble making this connection work in my current setup.

Has anyone else run into this issue? What’s the correct way to chain these nodes together when using AI Agent workflows?

I had the same exact problem when I started with AI Agent workflows in n8n. AI Agents handle data flow differently than regular workflows - they’ll try to process nodes in parallel instead of sequentially, which messes things up. After you connect your HTTP Request to the Function node, check the execution order first. Then in your Function node, add console.log('Received data:', JSON.stringify(items, null, 2)); to see what you’re actually getting from Google Places API. From what I’ve seen, the data usually sits under items[0].json.results for Google Places. So your filtering code should look like: const places = items[0].json.results; return [{ json: { filtered_places: places.filter(place => place.rating >= 4.0).slice(0, 10) } }]; The return format matters - you’ve got to wrap your processed data back into n8n’s item structure or it won’t work.

hey, it’s pretty simple! just drag the connection dot from ur HTTP request node to the function node. then, in the function, use items[0].json to access the data from the API. hope this helps!

AI Agent workflows are tricky - they wrap your data in extra layers. I’ve hit this same issue multiple times building restaurant recommendation systems.

Connecting’s easy: drag HTTP Request output to Function input. But AI Agents handle data differently than regular n8n flows, which trips everyone up.

Don’t guess the data structure. Drop this at the top of your Function node:

console.log('Full input structure:', JSON.stringify($input.all(), null, 2));

This shows exactly what Google Places sends. It’s usually nested under $input.first().json.candidates or $input.first().json.results.

Once you see the structure, filtering’s simple:

const places = $input.first().json.results || [];
const filtered = places
  .filter(place => place.rating && place.rating > 4)
  .slice(0, 10);
  
return [{ json: { restaurants: filtered } }];

That return format’s key - AI Agents need data wrapped in n8n’s item structure.

The connection should work fine - just drag from your HTTP Request node output to your Function node input. The tricky bit is that AI Agent workflows can have different data structures than regular n8n flows. First thing I’d do is console.log the incoming data in your Function node to see exactly what you’re working with. For filtering restaurants above 4 stars and limiting to 10 results, try return items.filter(item => item.json.rating > 4).slice(0, 10); but you’ll need to adjust the data path based on how Google Places actually returns stuff. AI Agent wrapper sometimes adds extra layers, so check the actual format first - it’ll save you a ton of headaches.