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 setup.

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

Has anyone dealt with this before? What’s the proper way to chain these nodes together in an AI Agent context?

Just drag from the HTTP Request output to the Function node input. The tricky part is handling the data structure - Google Places API returns nested JSON, so you need the right path. Use const places = $input.first().json.results to grab the restaurant array. Then filter like this: places.filter(restaurant => restaurant.rating >= 4.0).slice(0, 10). Watch out though - some places don’t have ratings, which’ll break your filter. Add this check: restaurant.rating && restaurant.rating >= 4.0. Also double-check your HTTP Request node returns the full response body, not just status codes, or your Function node won’t have any data to work with.

AI Agent workflows handle node connections differently than regular n8n setups. When you link your HTTP Request node to the Function node, make sure you’re connecting to the right execution path - AI Agent nodes have multiple branches. In your Function node, grab the HTTP response data with $input.all()[0].json to pull results from the Places API. Filter for places with 4+ star ratings and grab the first 10 entries: return $input.all()[0].json.results.filter(place => place.rating > 4).slice(0, 10). Don’t forget error handling between nodes - if your HTTP request fails, your Function node won’t run. Add some conditional logic or try-catch to handle cases where the API response doesn’t match what you expect.