# Msg root to file

**URL:** <https://discourse.nodered.org/t/msg-root-to-file/3943>\
**Category:** General\
**Created:** [12 October 2018 21:47 UTC](https://discourse.nodered.org/t/msg-root-to-file/3943 "2018-10-12T21:47:31Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [12 October 2018 21:47 UTC](https://discourse.nodered.org/t/msg-root-to-file/3943/1 "2018-10-12T21:47:31Z")

</div>

I'm using the Azure IoT hub palette to resgister a device which responds with a key. This key I'm trying to save into a file but the Azure node responds back with msg and not msg.payload so the file node is not catching anything.

I also tried using change to move msg to msg.payload before the file node but it doesn't like it when I leave the source as just msg (blank).

anyone know how to capture the msg root itself?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [12 October 2018 22:15 UTC](https://discourse.nodered.org/t/msg-root-to-file/3943/2 "2018-10-12T22:15:02Z")

</div>

can you send the whole msg to a debug node and see what it contains ? (You have to configure the debug node to see complete msg). It can't really just be sending msg as all msg have to be objects.

PS don't paste the key here 🙂

---

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [13 October 2018 00:16 UTC](https://discourse.nodered.org/t/msg-root-to-file/3943/3 "2018-10-13T00:16:13Z")

</div>

Funny enough that's how I found out there wasn't any properties on msg.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/68d1ee68f260d71dff5738f4afea64994baf3433.png)

---

<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:** [13 October 2018 00:32 UTC](https://discourse.nodered.org/t/msg-root-to-file/3943/4 "2018-10-13T00:32:16Z")

</div>

That's just completely wrong. An issue needs to be raised against whatever node is sending a string as a message.

---

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [13 October 2018 00:33 UTC](https://discourse.nodered.org/t/msg-root-to-file/3943/5 "2018-10-13T00:33:45Z")

</div>

I guess I'll open an issue on the authors GitHub. I'm new to node-red so I wasn't sure if i was doing something wrong.

---

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [15 October 2018 12:33 UTC](https://discourse.nodered.org/t/msg-root-to-file/3943/6 "2018-10-15T12:33:17Z")

</div>

Just out of curiosity, would I be able to use a function node to capture the string and output it as the payload object?

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [15 October 2018 14:22 UTC](https://discourse.nodered.org/t/msg-root-to-file/3943/7 "2018-10-15T14:22:00Z")

</div>

> [@injector22](#):
>
> Just out of curiosity, would I be able to use a function node to capture the string and output it as the payload object?

Is that debug display showing the whole msg object or is it showing the msg.payload? If the former then you can't even expect any of the nodes to handle a string instead of an object as a msg - though some will likely have catered for it. If it is msg.payload then you can handle it normally.

---

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [15 October 2018 18:06 UTC](https://discourse.nodered.org/t/msg-root-to-file/3943/8 "2018-10-15T18:06:49Z")

</div>

Yes, debug is set to display the whole msg. The output from the node is a string not an object (payload), hence the predicament. I was simply wondering if there was anything I could do on my end instead of waiting for the author to fix the node.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 October 2018 18:16 UTC](https://discourse.nodered.org/t/msg-root-to-file/3943/9 "2018-10-15T18:16:28Z")

</div>

did you try a function node just looking at msg like you suggested ? If in doubt try it 🙂

---

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [15 October 2018 18:52 UTC](https://discourse.nodered.org/t/msg-root-to-file/3943/10 "2018-10-15T18:52:00Z")

</div>

Yea i gave it a try but nothing was captured.

---

<div class="post-metadata">

**Author:** ![injector22](https://avatars.discourse-cdn.com/v4/letter/i/e9bcb4/32.png) [@injector22](https://discourse.nodered.org/u/injector22)\
**Post date:** [17 October 2018 12:23 UTC](https://discourse.nodered.org/t/msg-root-to-file/3943/12 "2018-10-17T12:23:39Z")

</div>

Just in case anyone else ends up with the same issue (not being able to get errors during the device registration to the Azure IoT hub) I'm adding my code below.

```
var iothub = global.get('iothub'); //needs to have settings.js modification
var connectionString = '';
var registry = iothub.Registry.fromConnectionString(connectionString);

// Create a new device
var device = {
    deviceId: msg.piInfo.deviceId
};

registry.create(device, function(err, deviceInfo, res) {
    if (err) node.send({hubError:err.toString()});
    if (res) node.send({hubResponse:res.statusMessage});
    if (deviceInfo) node.send({hubInfo:deviceInfo});
});

return msg;
```
