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

I’m pretty new to n8n and programming overall, so this is probably a basic question. I can’t figure out how to link a Function node to an HTTP Request node when working within an AI Agent.

Basically what I’m trying to do is make an HTTP call to the Google Places API to find new dining spots around my area. After getting the response, I want to use a Function node to filter the data so it only shows places with ratings above 4 stars and limits the output to just 10 results. Everything I’ve found online suggests connecting the HTTP request with a function node to process the data, but I’m having trouble making this connection work in this specific setup.

Node execution order is crucial with AI Agents - way more than regular workflows. Once you’ve connected your HTTP Request to the Function node, make sure your HTTP node actually returns JSON data properly. In the Function node, grab the Places API response from the input data and apply your filters. Try something like filtering where item.rating >= 4, then use slice(0, 10) to cap your results. I ran into the same thing when I started - connecting the nodes is easy, but getting the data handling right in the Function node took some experimenting.

AI Agent workflows handle HTTP responses differently than regular n8n workflows - that’s the key thing to know.

When you chain HTTP Request → Function, the Google Places API response gets wrapped in extra metadata. In your Function node, grab the actual places data like this:

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

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

I’ve built similar location filters before - the main gotcha is Google Places sometimes returns places with no ratings. That’s why I added the place.rating && check.

Also double-check your HTTP Request node has the right Google Places API endpoint and your API key works. The Function node won’t save you if the HTTP request fails silently.

just drag the dot from your HTTP req node over to the function node input. make sure your http node runs first, then in your func use $input.all() to filter for places 4 stars and up.

The connection works just like regular workflows, but there’s one thing about error handling in AI Agent contexts that caught me off guard. Your Function node needs to handle cases where the HTTP Request returns empty results or API errors from Google Places. I’d add a check at the start of your Function node to verify the HTTP response structure before filtering. Check if the response has a ‘results’ property and isn’t empty. Google Places API can be finicky with location queries - sometimes it returns zero results even for valid areas. Also - if you’re testing this, make sure your Google Places API key has the Places API enabled in Google Cloud Console. I wasted way too much time debugging my Function node logic when the real issue was API permissions. The HTTP Request node will still execute but return error responses that your Function node then tries to process as valid place data.

here’s what works for ai agents: always check your http node output before writing any function logic. just run the http req by itself to see what google places actually sends back, then build your function around that structure. the json nesting’s often diff than you’d expect.