# "HTTP Request Node" seems to overwrite all sub-strings in "msg.payload", elegant solution for working around this?

**URL:** <https://discourse.nodered.org/t/http-request-node-seems-to-overwrite-all-sub-strings-in-msg-payload-elegant-solution-for-working-around-this/87021>\
**Category:** General\
**Tags:** http-request, function-node\
**Created:** [5 April 2024 05:36 UTC](https://discourse.nodered.org/t/http-request-node-seems-to-overwrite-all-sub-strings-in-msg-payload-elegant-solution-for-working-around-this/87021 "2024-04-05T05:36:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![EpicLPer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/epiclper/32/89899_2.png) [@EpicLPer](https://discourse.nodered.org/u/EpicLPer)\
**Post date:** [5 April 2024 05:36 UTC](https://discourse.nodered.org/t/http-request-node-seems-to-overwrite-all-sub-strings-in-msg-payload-elegant-solution-for-working-around-this/87021/1 "2024-04-05T05:36:29Z")

</div>

Heya,

somewhat new-ish to Node-RED in general so sorry if this might sound noobish 🙂

In short I'm making a REST API call via the "HTTP Request Node" from a Telegram chat command, the Telegram node appends some sub-strings to "msg.payload" such as "msg.payload.chatId" etc.  
I've added the HTTP Request Node after the Telegram receive node, however it seems that once the request node finished doing it's thing it completely wipes the "msg.payload" clean and overwrite whatever was already there. The "msg.payload.chatId" as example is no longer present after it.  
I couldn't work around this cause both nodes receive/output as "msg.payload" and I can't seem to change this.

Is this intended behavior? If so, what is a good/elegant way to work around this and "merge" multiple "msg.payload" sub-strings so it becomes one big payload? I tried `msg.payload = msg.telegram_node;`  
but this also overwrites every sub-string.  
My current solution is to use the following which works but is rather hardcoded which I don't like too much ^^"

```auto
msg.payload.type = msg.telegram_node.type;
msg.payload.chatId = msg.telegram_node.chatId;

```

My current flow looks like this:

 ![msedge_2a0XHcOoLK](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/e/4e4255aa7ed6c7df0cfffd9709d1215b2e6b79a5.png)

Thanks already for your help!

---

<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:** [5 April 2024 06:06 UTC](https://discourse.nodered.org/t/http-request-node-seems-to-overwrite-all-sub-strings-in-msg-payload-elegant-solution-for-working-around-this/87021/2 "2024-04-05T06:06:35Z")

</div>

Hi and welcome.

Prior to http request node move your payload to another msg property, using a change node. You can then after the request recreate the payload you require, using the saved data in the other properties.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 April 2024 06:14 UTC](https://discourse.nodered.org/t/http-request-node-seems-to-overwrite-all-sub-strings-in-msg-payload-elegant-solution-for-working-around-this/87021/3 "2024-04-05T06:14:30Z")

</div>

Move any values that you want retained to different message properties, msg.chatId, msg.type etc.

A well behaved node will pass these message properties through unchanged.

The no-code way to do this is with a change node.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/8/4833dc23ad9957eee14e97cb4d732a3e383f45c6.png)

---

<div class="post-metadata">

**Author:** ![EpicLPer](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/epiclper/32/89899_2.png) [@EpicLPer](https://discourse.nodered.org/u/EpicLPer)\
**Post date:** [5 April 2024 10:02 UTC](https://discourse.nodered.org/t/http-request-node-seems-to-overwrite-all-sub-strings-in-msg-payload-elegant-solution-for-working-around-this/87021/4 "2024-04-05T10:02:06Z")

</div>

Can I somehow "merge" 2 different payloads afterwards without knowing what sub-values either of them have? So, as example:  
`msg.payload.chatId` will be moved to `msg.telegram_node.chatId`, but meanwhile the HTTP Request generates a `msg.payload.version`. I later want to combine everything into a single `msg.payload` with all sub-values from all payloads without knowing what kind of sub-values either the HTTP Request `payload` or `telegram_node` has now.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [5 April 2024 10:22 UTC](https://discourse.nodered.org/t/http-request-node-seems-to-overwrite-all-sub-strings-in-msg-payload-elegant-solution-for-working-around-this/87021/5 "2024-04-05T10:22:06Z")

</div>

> [@EpicLPer](#):
>
> Can I somehow "merge" 2 different payloads afterwards without knowing what sub-values either of them have?

In a `function` node you could do the following to merge the two objects:

```auto
msg.payload = { ...msg.payload, ...msg.telegram_node }
return msg

```

Note that if both `msg.payload` and `msg.telegram_node` have a property with the same name, then the resulting object will only have the value from the `telegram_node` (because of the order I put them in the statement above).

---

<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:** [19 April 2024 10:22 UTC](https://discourse.nodered.org/t/http-request-node-seems-to-overwrite-all-sub-strings-in-msg-payload-elegant-solution-for-working-around-this/87021/6 "2024-04-19T10:22:30Z")

</div>

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