# Combine similar payloads then split

**URL:** <https://discourse.nodered.org/t/combine-similar-payloads-then-split/24284>\
**Category:** General\
**Created:** [5 April 2020 19:23 UTC](https://discourse.nodered.org/t/combine-similar-payloads-then-split/24284 "2020-04-05T19:23:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![srynearson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/srynearson/32/19230_2.png) [@srynearson](https://discourse.nodered.org/u/srynearson)\
**Post date:** [5 April 2020 19:23 UTC](https://discourse.nodered.org/t/combine-similar-payloads-then-split/24284/1 "2020-04-05T19:23:50Z")

</div>

Hi all, I am trying to combine two streams of data. One feed has some of the attributes I need, and the other has the rest. Each stream has many nodes but most of the nodes can be singled out in each stream by their MAC address. I have attempted to combine the attributes of each one. I finally have both streams into one message payload separated further into payloads part 1 and part 2. I cant seem to combine like parts 1 and 2. Any suggestions?

Thanks again 🙂

**My Flow**

```auto
[{"id":"e21cc72a.85b078","type":"http request","z":"a61db8ad.cd7c68","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"https://10.254.1.19/api/v1/location","tls":"8b3830a0.cd07c","persist":false,"proxy":"","authType":"basic","x":150,"y":120,"wires":[["f58ab2a8.69306"]]},{"id":"f58ab2a8.69306","type":"change","z":"a61db8ad.cd7c68","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.Location_result","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":120,"wires":[["5c1752eb.aa83dc"]]},{"id":"3eddda3d.6710e6","type":"inject","z":"a61db8ad.cd7c68","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":190,"y":320,"wires":[["3708805d.dcb4e","e21cc72a.85b078"]]},{"id":"5c1752eb.aa83dc","type":"split","z":"a61db8ad.cd7c68","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":true,"addname":"","x":490,"y":120,"wires":[["923aa877.bbff28"]]},{"id":"3708805d.dcb4e","type":"http request","z":"a61db8ad.cd7c68","name":"","method":"GET","ret":"obj","paytoqs":false,"url":"https://10.254.1.19/api/v1/station","tls":"8b3830a0.cd07c","persist":false,"proxy":"","authType":"basic","x":150,"y":40,"wires":[["7dbb06e9.5ef5c8"]]},{"id":"923aa877.bbff28","type":"change","z":"a61db8ad.cd7c68","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.msg","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":120,"wires":[["9a49840a.3b0428"]]},{"id":"7dbb06e9.5ef5c8","type":"change","z":"a61db8ad.cd7c68","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.Station_result","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":40,"wires":[["dc1eb92d.7e16f8"]]},{"id":"9a49840a.3b0428","type":"function","z":"a61db8ad.cd7c68","name":"","func":"var payload=msg.payload;\nmsg.payload = { \n \"mac_address\": payload.sta_eth_mac.addr,\n \"association\": payload.associated,\n \"x\": payload.sta_location_x,\n \"y\": payload.sta_location_y,\n \"alg\": payload.loc_algorithm,\n \"error_level\": payload.error_level,\n \"floor_id\": payload.floor_id }\nreturn msg;","outputs":1,"noerr":0,"x":710,"y":180,"wires":[["f8659fb8.cd32c"]]},{"id":"dc1eb92d.7e16f8","type":"split","z":"a61db8ad.cd7c68","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":490,"y":40,"wires":[["1cddd653.f9b0ea"]]},{"id":"f8659fb8.cd32c","type":"function","z":"a61db8ad.cd7c68","name":"","func":"var payload=msg.payload;\nmsg.topic = msg.payload.mac_address+\"_2\";\nreturn msg;","outputs":1,"noerr":0,"x":950,"y":120,"wires":[["991853c5.d60aa"]]},{"id":"1cddd653.f9b0ea","type":"change","z":"a61db8ad.cd7c68","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.msg","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":40,"wires":[["209bbafa.5e6d76"]]},{"id":"991853c5.d60aa","type":"join","z":"a61db8ad.cd7c68","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"5","count":"200","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":1100,"y":280,"wires":[["3e3215c3.4a614a"]]},{"id":"209bbafa.5e6d76","type":"function","z":"a61db8ad.cd7c68","name":"","func":"var payload=msg.payload;\nmsg.payload = { \"Username\": payload.username,\n \"role\": payload.role,\n \"type\": payload.device_type,\n \"mac_address\": payload.sta_eth_mac.addr,\n \"ip_address\": payload.sta_ip_address.addr,\n \"access_point\": payload.ap_name,\n \"bssid\": payload.bssid.addr}\nreturn msg;","outputs":1,"noerr":0,"x":790,"y":80,"wires":[["9af6712d.ae521"]]},{"id":"9af6712d.ae521","type":"function","z":"a61db8ad.cd7c68","name":"","func":"var payload=msg.payload;\nmsg.topic = msg.payload.mac_address+\"_1\";\nreturn msg;","outputs":1,"noerr":0,"x":1000,"y":40,"wires":[["991853c5.d60aa"]]},{"id":"3e3215c3.4a614a","type":"debug","z":"a61db8ad.cd7c68","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1070,"y":360,"wires":[]},{"id":"8b3830a0.cd07c","type":"tls-config","z":"","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false}]

```

**what returns**  
Was two long to past into code. so I attached.. and you have to see the beginning and end to see there is two payloads for each mac.. "mac"\_1 and "mac"\_2. Attached an image as well to see.

[return.json](https://discourse.nodered.org/uploads/short-url/txRhdBEx2EqPo2Glr54OKYJyYOI.json) (4.4 KB)

 ![7](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/9361b5e425f9bf1b65bbc450c956d4a96f26be14.png)

I'd love to get them into individual messages with the attributes from "mac"\_1 and "mac"\_2.

Also, if I am doing this totally wrong, just let me know. Learning as I go.

---

<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:** [5 April 2020 20:39 UTC](https://discourse.nodered.org/t/combine-similar-payloads-then-split/24284/2 "2020-04-05T20:39:20Z")

</div>

I can't test your flow at the moment, but have you combined the streams using the Join node in key/value mode as described in [this post from the cookbook](https://cookbook.nodered.org/basic/join-streams). That is an effective way of doing it with minimum effort.

---

<div class="post-metadata">

**Author:** ![srynearson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/srynearson/32/19230_2.png) [@srynearson](https://discourse.nodered.org/u/srynearson)\
**Post date:** [5 April 2020 21:24 UTC](https://discourse.nodered.org/t/combine-similar-payloads-then-split/24284/3 "2020-04-05T21:24:23Z")

</div>

Join is what I am attempting to use. If I have SAME message topics come in, only one of the sets of attributes is added. If I make the topics coming from the two incoming flows "mac"\_1 and "mac"\_2, at least I have all the data from both flows in the final payload. But then I am not sure how to get the data from payloads "mac"\_1 and "mac"\_2 into one message for each set of message topics.

 ![8](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/f/aff484caac99cfa7936d74a205d96cb5e86f13f3.png)

so far my flows call api, split it into individual messages, formatted how I wanted, then applied the topic "mac"\_1 and "mac"\_2 to each message depending on the stream.

how can I look for topics matching "mac"\_1 and "mac"\_2 and then combine the payloads. Used the join node in all configurations its seems lolBugged me all night lol

Thank you so much for your assistance.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [6 April 2020 09:08 UTC](https://discourse.nodered.org/t/combine-similar-payloads-then-split/24284/4 "2020-04-06T09:08:36Z")

</div>

Could you please provide some test data - the output from the two `http request` nodes.

---

<div class="post-metadata">

**Author:** ![srynearson](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/srynearson/32/19230_2.png) [@srynearson](https://discourse.nodered.org/u/srynearson)\
**Post date:** [9 April 2020 19:08 UTC](https://discourse.nodered.org/t/combine-similar-payloads-then-split/24284/5 "2020-04-09T19:08:52Z")

</div>

I was able to figure it out. Thank you!

---

<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:** [8 June 2020 19:08 UTC](https://discourse.nodered.org/t/combine-similar-payloads-then-split/24284/6 "2020-06-08T19:08:54Z")

</div>

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