HTTP Request node: JSON "text": issue for sending output of AI Agent to a Google Docs file

Problem statement: I am using n8n to output the response of an AI Agent to Google Docs unformatted via an HTTP Request node POST request. I am struggling with the “text”: formatting. Either it’s not proper JSON, or my formatting causes n8n to not recognize the AI Agent node.

What is the error message (if any)? “JSON parameter needs to be valid JSON”

Please share your workflow

Share the output returned by the last node

The UI shows n8n doing the text translation for the JSON Message body in the UI itself, but when I test, it says invalid JSON. in the JS expression, proper JSON, I believe is to escape what’s in quotes ' or ":
{
“requests”: [
{
“insertText”: {
“location”: {
“index”: 1
},
“text”: “{{ $node[‘AI Agent’].json[‘output’] }}”
}
}
]
}

Information on your n8n setup

  • n8n version: 1.91.2
  • **Database (default: SQLite):**default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): default, I think
  • Running n8n via (Docker, npm, n8n cloud, desktop app): npm
  • Operating system: windows 11
1 Like

See if you can use the technique described in this post.

@hubschrauber

Struggling a bit to translate that person’s shopify example into my example “InsertText” HTTP POST request: If I try to convert the whole this to js, n8n gives me invalid syntax… Note, I am a bit new to JSON and js, so I’m going to say that’s the issue. I think I’m way off with this example:

from what I had that doesn’t work:

{
  "requests": [
    {
      "insertText": {
        "location": {
          "index": 1
        },
        "text": {{ $node["AI Agent"].json["output"] + "\n" }}
      }
    }
  ]
}

to even worse, I think :

{{
 {
  type: "requests"
  command: "insertText"
  location: "location"
  index: "index"
  text: "text"
  output: "output"

type: [  { command: { location : { index: 1 }, text: "\n"+ ${"AI Agent"}.json.output + "\n" } } ] }.toJsonString() }}

I think that shopify example and my lack of experience is confusing me. When you sav to convert the whole thing to an expression, I think that my example above is an attempt to do that, but I need some help with that given my lack of js experience…

your original workflow works when i tried it. maybe you can show us what kind of error you get?

  1. Your js object is missing commas after each attribute
  2. Your reference to the previous node doesn’t follow n8n’s syntax.
    • $('AI Agent').item.json.output
    • not ${'AI Agent'}.json.output

This article might help you see the difference between a js object and JSON.
Both of them roughly follow the structure described in this reference.

Corrected example with both structures using the “full js object” → JSON expression.

@hubschrauber I went with Structure 1 - a simple correction to my mistakes in translating the JSON to JS and that worked with n8n and my agent. Thank you!

1 Like

JSON error - something like " encountered, string expected" - using the syntax provided by @hubschrauber in structure 1 solved the issue.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.