String input to HTTP Request

The problem/error/question

I am trying to pass a content from Google Docs to a HTTP request. After viewing the content is ready in the previous node, I pass this content to OpenAI’s responses API as user input_text.

{
  "role": "user",
  "content": [
    {
      "type": "input_text",
      "text": "{{ $json.content }}"

    }
  ]
}

“text”: “{{ $json.content }}” this causes the error. Having a constant string, I can send the request. But cant use the input from previous code node.

The error message

JSON parameter needs to be valid JSON

My workflow

{
“nodes”: [
{
“parameters”: {
“method”: “POST”,
“url”: “https://api.openai.com/v1/responses”,
“sendHeaders”: true,
“headerParameters”: {
“parameters”: [
{
“name”: “Content-Type”,
“value”: “application/json”
},
{
“name”: “Authorization”,
“value”: “Bearer Token”
}
]
},
“sendBody”: true,
“specifyBody”: “json”,
//here is the json input. When I write a constant string as text it workds
“jsonBody”: " {\n "role": "user",\n "content": [\n {\n "type": "input_text",\n "text": "{{ $json.content }}"\n\n }\n ]\n }\n ],\n "text": {\n "format": {\n "type": "text"\n }\n },\n "reasoning": {},\n "tools": ,\n "temperature": 1,\n "max_output_tokens": 2048,\n "top_p": 1,\n "store": true\n}",
“options”: {}
},
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4.2,
“position”: [
2960,
20
],
“id”: “myid”,
“name”: “HTTP Request4”
},
{
“parameters”: {
“jsCode”: “const items = $input.all();\n\nconst updatedItems = items.map((item) => {\n const cleanedContent = item.json.content.replace(/\n/g, " ");\n item.json.content = Source: blog-url Target: (some text)[some-text] ${cleanedContent};\n return item;\n});\n\nreturn updatedItems;”
},
“type”: “n8n-nodes-base.code”,
“typeVersion”: 2,
“position”: [
2760,
80
],
“id”: “a739d218-4bf6-498b-899a-8fb5464d8052”,
“name”: “Code1”
}
],
“connections”: {
“HTTP Request4”: {
“main”: [

]
},
“Code1”: {
“main”: [
[
{
“node”: “HTTP Request4”,
“type”: “main”,
“index”: 0
}
]
]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “instanceID”
}
}

Output returned by the last node

{
“documentId”: “my_document_id”,
“content”: “Source: blog-url Target: (some word)[some-word] Content”
}

JSON parameter needs to be valid JSON

Information on your n8n setup

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

Hi @gokitor,

I tried to replicate your json in n8n. Is this what you are trying to do?

also, when uploading a workflow put it into the format below. Then it will render as a workflow…
"

type or paste code here

"

Hey rbreen,

Thanks for the tip. My goal is to read a google docs and send its content as http request. Since I already have the content ready, I didnt include that part. So I am having difficulty to send the google docs content as json parameter. I assume it might be because of \n or other things the content has. I already try to replace them but doesnt help at all.

Best

1 Like
1 Like

@gokitor

I rewrote the code step so it outputs the content in json. Then you can use it in the html request step after.

Hi Robert,

Thanks for the help again. Unfortunately it still doesnt solve the problem. I believe its because of the output format of Google Doc’s content output logic. I decided to install the docx file and then send it as base64 to a lambda function to get the pure text.

Best,

GK

1 Like

Hi @gokitor,

Glad you got it to work!

Best,

Robert

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