HTTP Request - Response body is not valid JSON

I saw that this question has been asked before, but it was over two years ago and unfortunately doesn’t solve our problem.

We send an HTTP request with a JSON file via API to our own app, and the response is a JSON file.

Our app works perfectly with Zapier.

The request works several times, but then, for some reason, it stops working, and the error message appears: “HTTP Request - Response body is not valid JSON.”

If you trigger and test the node again after the error message, it works again.

All external tests run without problems. We log every input and output via the API on our app in a log file. We cannot detect any error in our code.


{
“nodes”: [
{
“parameters”: {
“method”: “POST”,
“url”: “https://avatar-app.klink-ai.com/api/v1/heygen_own_player”,
“sendHeaders”: true,
“headerParameters”: {
“parameters”: [
{
“name”: “x-api-key”,
“value”: “018889be4f5f4c01b3f8fa524403a969”
}
]
},
“sendBody”: true,
“specifyBody”: “json”,
“jsonBody”: “={\n "heygen_share_link":"{{ $(‘Heygen Share abrufen’).item.json.data }}",\n "player_embed_page": "https://www.chili-concept.de/de/fd0306-1-0-0-0\”,\n "campaign_id": "10000011",\n "heygen_callback_id": "",\n "customer_title": "",\n "customer_firstname": "",\n "customer_lastname": "",\n "customer_language": "de"\n}",
“options”: {
“response”: {
“response”: {
“fullResponse”: true,
“responseFormat”: “json”
}
}
}
},
“name”: “Klink API senden”,
“type”: “n8n-nodes-base.httpRequest”,
“typeVersion”: 4,
“position”: [
3280,
-100
],
“id”: “2a0c0bba-88b2-439e-a419-0cc9d9b5751f”,
“onError”: “continueErrorOutput”
}
],
“connections”: {
“Klink API senden”: {
“main”: [
,

]
}
},
“pinData”: {},
“meta”: {
“templateCredsSetupCompleted”: true,
“instanceId”: “492a22987093c89f92811b70f0ddbfefd0a42760c69f2bb0cbfe5530cf764949”
}
}

n8n Version 1.91.2
Database SQLite

  • n8n EXECUTIONS_PROCESS setting (default: own, main): (I don’t know, think default)
    Running n8n via Cloud
    Mac OSX, Chrome

We hope someone here has a tip as to why this error message appears and what we might be doing wrong.

Hi @KLINK-AI , welcome to the community!

Could you please try using:

"heygen_share_link": {{ JSON.stringify( $('Heygen Share abrufen').item.json.data ) }}

If that’s not the issue, please attach your workflow like this:

n8n attach workflow

This will make it readable and visible to everyone.

1 Like

@mohamed3nan Thank you for your quick reply and the tip, including how I can better share the workflow. I’ve already used the formula and am testing it. As soon as I’ve tested it several times, I’ll let you know the results.

1 Like

The first run went smoothly.

Unfortunately, the same error message appeared on the second run as described in my first post.

The error says:
image

Is there any reason to choose JSON?

Maybe just select “Autodetect”?

From our perspective, the app outputs JSON, so I also set JSON as the response format here.

I’ve switched it to AutoDect and am checking if it makes a difference. I’m curious to see the results.

With the Autodetect setting, it has now run three times without errors. Now, on the fourth test run, the message “Invalid JSON in response body” appears.

We have installed a logging process on our server, and every incoming and outgoing request is documented

We’re currently only testing with the three most important variables. All others are optional for later use.

Here is the log file entry from the last run where the error occurred in the n8n node.

2025-05-15 08:18:10:
======================== data sent from n8n to Klink API ======================== :
{
“heygen_share_link”: “HeyGen | <!-- -->Videobotschaft für Herr Jerry Lewis”,
“player_embed_page”: “Chiliconcept Christine Clemenz”,
“campaign_id”: “10000011”,
“heygen_callback_id”: “”,
“customer_title”: “”,
“customer_firstname”: “”,
“customer_lastname”: “”,
“customer_language”: “de”
}

Response from API (which is sent back to n8n):

2025-05-15 08:18:11:
http_response_code(201)
2025-05-15 08:18:11:
{
“status”: “Ok”,
“status_code”: 201,
“page_link_internal”: “Videobotschaft für Herr Jerry Lewis”,
“qrcode_img_link_internal”: “https://avatar-app.klink-ai.com/share/qr-int/10000011/3c93645ca432484b9eba1518119e5249-qr-int.png”,
“page_link_external”: “Chiliconcept Christine Clemenz”,
“qrcode_img_link_external”: “https://avatar-app.klink-ai.com/share/qr-ext/10000011/3c93645ca432484b9eba1518119e5249-qr-ext.png”,
“heygen_video_id”: “6c68abfab1a24acaa6bc9d29a723e70c”,
“heygen_callback_id”: “”,
“heygen_video_title”: “Videobotschaft für Herr Jerry Lewis”,
“heygen_share_link”: “HeyGen | <!-- -->Videobotschaft für Herr Jerry Lewis”,
“heygen_video_gif_url”: “https://resource2.heygen.ai/gif/6532d5d38f7b4430a239f0af4f92a0ab.gif”,
“heygen_video_ratio”: “16:9”,
“heygen_video_720p_video_url”: null,
“heygen_video_720p_poster”: null,
“heygen_video_720p_width”: null,
“heygen_video_720p_height”: null
}

========================

I did two more test runs, but unfortunately they all failed with the same error message!

@KLINK-AI

I’m trying to reproduce the error, but I can’t replicate it

Maybe output to text first like @mohamed3nan said.

And validate the text why it can not convert to json?

Should be some strange character in the response.

Hi @mohamed3nan , hi @darrell_tw

Thank you for your inputs and help.

I spent the whole day today running numerous tests and investigating everything with my app programmer. We discovered an irregularity in the process on our app that accesses external data links from Heygen after the API call.

We discovered that Heygen requires different runtimes to generate the various retrieval links. When it took a little longer for some of the URLs to be completed, the variables in our database remained empty and were returned as “NULL” in the response, without quotes, thus generating invalid JSON.

We’ve now placed a 30-second wait node between the Heygen request and the request to the KLINK app to ensure that the information is provided by Heygen. We encountered one error at 20 seconds in our tests.

After 40 test rounds, things are looking good, and we’re confident that was the cause.

3 Likes

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