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

I’m pretty new to n8n and programming overall, so hopefully this is straightforward to solve. I’m having trouble connecting a Function node to an HTTP Request node that’s part of an AI Agent setup.

Basically, I created an HTTP request that calls the Google Places API to find new dining spots around my area. I want to process the response data to show only places with ratings above 4 stars and limit it to the first 10 results. Everything I’ve found online mentions linking the HTTP request with a function node for data processing, but I can’t figure out how to make this connection work in my current setup.

Has anyone dealt with this before? What’s the proper way to chain these nodes together when working with AI Agent workflows?

hey! u just drag from the output dot of ur HTTP request and drop it onto the input of the function node. it’ll connect like magic. then in the function node, use items[0].json to filter out the stuff u don’t need. good luck!

Build it step by step to avoid headaches. First, run your HTTP Request node solo and check what Google Places actually returns - click the node after it runs to see the raw data structure.

Once you know the format, add your Function node and connect them (drag from the right circle of HTTP Request to the left circle of Function). I usually start with something like:

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

return filtered.map(place => ({
  json: {
    name: place.name,
    rating: place.rating,
    address: place.vicinity
  }
}));

Biggest thing I learned building similar workflows: always check for missing data - some places don’t have ratings. Also, return data in whatever format your AI Agent expects, not just the raw filtered array.

This video covers the Function node basics pretty well:

Test each node individually before connecting to your AI Agent. Makes debugging way easier when stuff breaks.

Wiring the HTTP Request to the Function node is easy - just drag between the connection points. What tripped me up was figuring out Google Places API’s data structure. The response comes back nested in a ‘results’ array, so you’ve got to access it right in your Function node. I’d suggest console.logging the whole response first to see what you’re dealing with before writing any filter logic. Once you see the structure, filtering for 4+ star ratings is just a basic filter method. Watch out for places without ratings though - handle those null values or your workflow will break. The AI Agent should grab the processed data from your Function node output no problem.

It’s pretty straightforward once you get the node flow down. After your HTTP Request node pulls data from Google Places API, drop in a Function node and connect them - just drag from the right circle of HTTP Request to the left circle of Function node. You’ll handle the data with JavaScript inside the Function node. The API response shows up as $input.all() or $input.first().json depending on your n8n version. For filtering, try something like const filteredPlaces = items[0].json.results.filter(place => place.rating > 4).slice(0, 10) to grab only top-rated spots and limit it to ten results. I’ve done this exact setup for location filtering in multiple workflows - just make sure your Function node spits out the data in whatever format your AI Agent expects downstream.

Classic beginner mistake - connecting is easy, but handling the data is where it gets messy. Double-check your Google Places API key permissions too. That’s usually what breaks things out of nowhere.