Optimizing response for n8n agent html request tool for API request

Hello!
I am trying to use the HTTP request tool for my N8N agent. I am successfully querying an API, but the response is a huge JSON which swamps the LLM I am using. I would like to programmatically reduce the size of the response by filtering out just the fields I want. There is the option to use the JavaScript expressions in the tool menu, so far I was unable to make it work - when I try to modify the $json variable it tries to work with the input for the tool (e.i. the prompt from the chat) not the response from the API, despite documentation saying it should work like this.
Could you please help me make this work? Thanks!

1 Like

Hey @AnarchistNerd! Could you share the workflow you have at this point? My suggestion would be instead of using $json to reference the HTTP node output itself. So something like $(‘HTTP Request’).item.json.output if “HTTP Request” is the name of your node and output is the field containing the JSON from the HTTP response.

See these docs for referencing outputs from specific nodes:

1 Like