# MQTT Additional Header/Payload

**URL:** <https://discourse.nodered.org/t/mqtt-additional-header-payload/20669>\
**Category:** General\
**Created:** [21 January 2020 05:48 UTC](https://discourse.nodered.org/t/mqtt-additional-header-payload/20669 "2020-01-21T05:48:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![crolshoven](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crolshoven/32/12366_2.png) [@crolshoven](https://discourse.nodered.org/u/crolshoven)\
**Post date:** [21 January 2020 05:48 UTC](https://discourse.nodered.org/t/mqtt-additional-header-payload/20669/1 "2020-01-21T05:48:27Z")

</div>

Hi guys,

First time working with MQTT and I'm excited how easy it was to setup the broker and configure 2 Clients in Node-Red to connect.

First a general question: Is it possible to send more than the "payload" via MQTT e.g. an additional Header?

In my case I receive an HTTP Call with a payload , which I send to the MQTT Broker. But I also need one of the objects from msg.res.xxx.xxx (doesn't really matter) to be send in the same call to the broker.  
I tried to just add the field to the payload via a function node, but on the subscribed client side just the "original" payload is received.

Function node:  
var payload=msg.payload; //get payload  
var parsedUrl=msg.req.\_parsedUrl.search;  
msg.payload.parsedUrl=parsedUrl;  
return msg;

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

Any idea?

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/6/3698a1c6d692df8faaefd447d71001bab89130bc.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/3/e32f5f26866f298f9468cbea4fc9d3c7c3b5a1ee.png)

---

<div class="post-metadata">

**Author:** ![crolshoven](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crolshoven/32/12366_2.png) [@crolshoven](https://discourse.nodered.org/u/crolshoven)\
**Post date:** [21 January 2020 06:29 UTC](https://discourse.nodered.org/t/mqtt-additional-header-payload/20669/2 "2020-01-21T06:29:08Z")

</div>

Hi again,

It seems that I can't change the payload due to the format? As changing the topic or adding another field is working fine.  
So rephrasing my question a little bit:  
Can I add an additional object send via MQTT. Something like "msg.header" or "msg.payload2" 😃

Or how to change the payload format? Trying to convert it to JSON String gives me the error "Ignored non-object payload"

Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![Christian-Me](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/christian-me/32/10774_2.png) [@Christian-Me](https://discourse.nodered.org/u/Christian-Me)\
**Post date:** [21 January 2020 07:03 UTC](https://discourse.nodered.org/t/mqtt-additional-header-payload/20669/3 "2020-01-21T07:03:43Z")

</div>

MQTT messages are generally a string sent to a specific topic. But you can send a json formatted object via mqtt and encode or decode it with the help of the json node.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 January 2020 08:43 UTC](https://discourse.nodered.org/t/mqtt-additional-header-payload/20669/4 "2020-01-21T08:43:35Z")

</div>

> [@crolshoven](#):
>
> Can I add an additional object send via MQTT. Something like "msg.header" or "msg.payload2"

No, but whatever you put in msg.payload should be sent to mqtt. Try this in your function node

```auto
msg.payload = {response: msg.payload, url: msg.req._parsedUrl.search
return msg;

```

Or you can do the same thing in a Change node.  
However, I don't see msg.req.\_parsedURL.search in your debug output, are you sure you don't mean `msg.req.url`?

---

<div class="post-metadata">

**Author:** ![crolshoven](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/crolshoven/32/12366_2.png) [@crolshoven](https://discourse.nodered.org/u/crolshoven)\
**Post date:** [21 January 2020 11:15 UTC](https://discourse.nodered.org/t/mqtt-additional-header-payload/20669/5 "2020-01-21T11:15:42Z")

</div>

Thanks for your reply.  
Yes, the msg.req.\_parsedUrl.search was just not on the screenshot.

If I use your code in the function node, no msg is getting out of the node. (checked with a debug node)

msg.payload = {response: msg.payload, url: msg.req.\_parsedUrl.search}  
return msg;

UPDATE: Sorry, my mistake. Works! 🙂
