# How to add ( or append ) new variables to a payload

**URL:** <https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499>\
**Category:** General\
**Tags:** function-node\
**Created:** [21 December 2021 00:07 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499 "2021-12-21T00:07:26Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![senzary](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@senzary](https://discourse.nodered.org/u/senzary)\
**Post date:** [21 December 2021 00:07 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499/1 "2021-12-21T00:07:26Z")

</div>

hello, i am new here and I am trying to add a variable devEui that will be eaul to a value received in payload

```auto
// new variable --           
var devEui =msg.end_device_id;
var http_packet = {
    payload: {
        data: msg.rx_data,
        network: "kerlinkSPN",
        source: "xxxxF53416",
        //inject new variable to data sent with payload -- >> **devEui: ??? ,**
    },
    headers: {
        "content-type": "application/json"
    }
}

return http_packet;

```

  

ADMIN Edit: Wrapped code in a code block (three backticks) for readability

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [21 December 2021 00:20 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499/2 "2021-12-21T00:20:11Z")

</div>

Just set  
payload.devEui = 'your content';

---

<div class="post-metadata">

**Author:** ![senzary](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@senzary](https://discourse.nodered.org/u/senzary)\
**Post date:** [21 December 2021 01:56 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499/3 "2021-12-21T01:56:29Z")

</div>

Thanks !  
If.the Content is another variable coming from the telemetry what is the sintaxis ?

The variable that comes is  
"Device\_end\_id" and the value ( deveui) has to be assigned to devEui  
Which is the value recognized by the mqtt broker

---

<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 December 2021 08:52 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499/4 "2021-12-21T08:52:39Z")

</div>

If `Device_end_id` is already a javascript variable then all you need is  
`http_packet.payload.devEui = Device_end_id`  
However, I suspect that Device\_end\_id may not be a simple javascript variable of that name. If so then give us more information about what that variable is.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 December 2021 10:34 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499/5 "2021-12-21T10:34:10Z")

</div>

> [@senzary](#):
>
> I am trying to add a variable devEui that will be eaul to a value received in payload

Add it like the `data` variable

```auto
var devEui =msg.end_device_id;
var http_packet = {
    payload: {
        data: msg.rx_data,
        network: "kerlinkSPN",
        source: "xxxxF53416",
        devEui: devEui // <<---- add devEui to payload
    },
    headers: {
        "content-type": "application/json"
    }
}

return http_packet;

```

alternatively...

```auto
var devEui =msg.end_device_id;
var http_packet = {
    payload: {
        data: msg.rx_data,
        network: "kerlinkSPN",
        source: "xxxxF53416",
    },
    headers: {
        "content-type": "application/json"
    }
}

http_packet.payload.devEui = devEui // <<---- add devEui to payload

return http_packet;

```

---

<div class="post-metadata">

**Author:** ![senzary](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@senzary](https://discourse.nodered.org/u/senzary)\
**Post date:** [21 December 2021 14:22 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499/6 "2021-12-21T14:22:27Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/28eed35ab112de40f6295aa6b7b79a8afe24f050.png)

---

<div class="post-metadata">

**Author:** ![senzary](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@senzary](https://discourse.nodered.org/u/senzary)\
**Post date:** [21 December 2021 14:23 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499/7 "2021-12-21T14:23:22Z")

</div>

it should work ! ☹

the other TWO VARIABLES network and source come in at the end, but not devEui

---

<div class="post-metadata">

**Author:** ![senzary](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@senzary](https://discourse.nodered.org/u/senzary)\
**Post date:** [21 December 2021 14:24 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499/8 "2021-12-21T14:24:52Z")

</div>

replaced deEui with ": test" and it works  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/6/36861ad3ff0eabf18b23d4f8b37634b2ffc4f6cf.png)

so the problem is in getting the telemetry value from end\_device\_id

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 December 2021 14:29 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499/9 "2021-12-21T14:29:43Z")

</div>

> [@senzary](#):
>
> so the problem is in getting the telemetry value from end\_device\_id

You are using `msg.end_device_id` have you checked the msg BEFORE it goes in to the function?

**Canned text...**  
There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

Just remember to prefix the copied path with `msg.`

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [21 December 2021 14:31 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499/10 "2021-12-21T14:31:02Z")

</div>

> **hint**
>
> it's probably msg.payload.data.end\_device\_id

---

<div class="post-metadata">

**Author:** ![senzary](https://avatars.discourse-cdn.com/v4/letter/s/f19dbf/32.png) [@senzary](https://discourse.nodered.org/u/senzary)\
**Post date:** [23 December 2021 20:49 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499/11 "2021-12-23T20:49:20Z")

</div>

thank you ALL.. still working on the receiving end, since the dveui data finally was created, but it goes as header information , not part of the "telemetry" .. next to solve  
solution

```auto
var devEui = msg.rx_data.end_device_id;

```

---

<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:** [6 January 2022 20:49 UTC](https://discourse.nodered.org/t/how-to-add-or-append-new-variables-to-a-payload/55499/12 "2022-01-06T20:49:24Z")

</div>

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