# HTTP IN node (POST) truncating body

**URL:** <https://discourse.nodered.org/t/http-in-node-post-truncating-body/88067>\
**Category:** General\
**Created:** [17 May 2024 16:31 UTC](https://discourse.nodered.org/t/http-in-node-post-truncating-body/88067 "2024-05-17T16:31:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlanGreyjoy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alangreyjoy/32/91062_2.png) [@AlanGreyjoy](https://discourse.nodered.org/u/AlanGreyjoy)\
**Post date:** [17 May 2024 16:31 UTC](https://discourse.nodered.org/t/http-in-node-post-truncating-body/88067/1 "2024-05-17T16:31:21Z")

</div>

Hello!

**The issue:**  
It seems the HTTP IN node is truncating the body if it's too large. When I attempt to  
`JSON.parse(msg.payload.files)`  
I get `SyntaxError: Unexpected token ' in JSON at position 1`  
_Which makes sense, since msg.payload.files is truncated._

**Details**  
I have an https in endpoint that is open to my carrier (VoIP)

This endpoint accepts two types of data, SMS and MMS. I have a switch node added to switch between  
`msg.payload.type ('incomingWebhookSMS' or 'incomingWebhookMMS')`

The data that my carrier sends me is this format:

SMS

```auto
{
    "type": "incomingWebhookSMS",
    "destination_number": "XXXXXXXXXX",
    "caller_id_number": "XXXXXXXXXX",
    "text": "Hello world!"
}

```

MMS

```auto
{
    "type": "incomingWebhookMMS",
    "to": "XXXXXXXXXX",
    "from": "XXXXXXXXXX",
    "text": "",
    "files": "{'d3c4090f-d23f-4945-8f44-faee2fb7af3c_123_1.jpeg': '/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAUDBAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIChALCAgOCQgIDRUNDhERExMTCAsWGBYSGBASExIBBQUFCAcIDwkJDxIPDw8SEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEv/AABEICtoFBAMBIgACEQEDEQH/xAAdAAEAAAcBAQAAAAAAAAAAAAAAAgMEBQYHCAEJ/8QAbhAAAQMCAQYIBgoKDQcKBQIHAQACAwQRBQYSEyExUQcIFEFhkaHRIjJScYGxFSNCU2JyksHS4RYzNXSCk7KztPAJGCQ0NlRVc3WUosLTF0OVo8PU1SVERWNkg4SFxPEmN6SlteNW4nbFRmblZf/EABwBAQADAQEBAQEAAAAAAAAAAAABAgMEBQYHCP/EAEgRAQABAwEEBggEBAMGBQUBAQABAgMRBBIhMVEFE0FhcZEUIjJSgaGx0RUzwfA0QnLhBiOyYnOCkqLxB0NTY8IWJCWz4tJ0/9oADAMBAAIRAxEAPwDeyIi818uzWkkz42O8pjT6SBdTVb8n5M6Bvw...",
    "destination_number": "XXXXXXXXXX",
    "caller_id_number": "XXXXXXXXXX"
}

```

As you can see, "files" is being truncated. How can I fix this?

**Things I have tried**  
I have set

```auto
/** The maximum size of HTTP request that will be accepted by the runtime api.
     * Default: 5mb
     */
    apiMaxLength: '1000mb',

```

I started out with 50mb, then 100mb, and 1000mb and still no luck.

Thanks for reading!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [17 May 2024 16:37 UTC](https://discourse.nodered.org/t/http-in-node-post-truncating-body/88067/2 "2024-05-17T16:37:34Z")

</div>

msg.payload.file is not truncated it is just shown that way in th debug sidebar, to save overheads of displaying large values.  
send it to console using debug node and you will see it all.

The error you get is that msg.payload.file is not a json, it is more likely to be a binary format or base64 encoded. You need to work out what format the api sends the image in.

---

<div class="post-metadata">

**Author:** ![AlanGreyjoy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alangreyjoy/32/91062_2.png) [@AlanGreyjoy](https://discourse.nodered.org/u/AlanGreyjoy)\
**Post date:** [17 May 2024 16:51 UTC](https://discourse.nodered.org/t/http-in-node-post-truncating-body/88067/3 "2024-05-17T16:51:11Z")

</div>

I didn't think to console log it.

I'll do that now.

But my js is identical to my prod node.js server. I am just moving all that code off my prod nodejs to node-red. Node-RED is way to awesome to be handjobing all this code haha.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [17 May 2024 16:55 UTC](https://discourse.nodered.org/t/http-in-node-post-truncating-body/88067/4 "2024-05-17T16:55:23Z")

</div>

One other thing, the headers from the http in node should give a clue to the file format is. Set the debug node to complete message object to see all the data

Looking again msg.files has single quotes which is not valid JSON, try replacing them with double quotes.

---

<div class="post-metadata">

**Author:** ![AlanGreyjoy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alangreyjoy/32/91062_2.png) [@AlanGreyjoy](https://discourse.nodered.org/u/AlanGreyjoy)\
**Post date:** [17 May 2024 17:01 UTC](https://discourse.nodered.org/t/http-in-node-post-truncating-body/88067/5 "2024-05-17T17:01:16Z")

</div>

Yup.. missed that when moving my code over.

```auto
const filesObject = JSON.parse(msg.payload.files.replace(/'/g, '"'))

```

All good now 🥹!

Console log showed full body too.

Node-RED is so awesome haha. I feel like I am cheating!

I started this little repo a couple of days ago

> **[GitHub - AlanGreyjoy/node-red-cpaas-apidaze](https://github.com/AlanGreyjoy/node-red-cpaas-apidaze)**
>
> Contribute to AlanGreyjoy/node-red-cpaas-apidaze development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 August 2024 17:01 UTC](https://discourse.nodered.org/t/http-in-node-post-truncating-body/88067/6 "2024-08-15T17:01:49Z")

</div>

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