Here is the flow.
I have two data objects get from two APIs. Object 1 returns the payload1, and has 5 attributes. Object 2 returns the payload2 and has 2 attributes. Both objects 1 and 2 have the same attribute "place". I want to merge the object when they have the same value of "place". So the final data object will have 6 attributes (because the "place" is same).
How can I do it? Thank you so much!
[
{
"id": "3c5de79e.539108",
"type": "tab",
"label": "flow 1",
"disabled": true,
"info": ""
},
{
"id": "eb9b21ca8f6c20f9",
"type": "http request",
"z": "3c5de79e.539108",
"name": "",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://www.geodetic.gov.hk/lpapi/?db=all",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 270,
"y": 180,
"wires": [
[
"4ee93f399d7d6d1f",
"a1f436e1f8831be3"
]
]
},
{
"id": "679763c87210febb",
"type": "inject",
"z": "3c5de79e.539108",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "600",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 90,
"y": 180,
"wires": [
[
"eb9b21ca8f6c20f9",
"fc28f3aa6bf7f897"
]
]
},
{
"id": "4ee93f399d7d6d1f",
"type": "split",
"z": "3c5de79e.539108",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 450,
"y": 180,
"wires": [
[
"85fc228bc02bcce5"
]
]
},
{
"id": "a1f436e1f8831be3",
"type": "debug",
"z": "3c5de79e.539108",
"name": "check object",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 290,
"y": 80,
"wires": []
},
{
"id": "85fc228bc02bcce5",
"type": "loop",
"z": "3c5de79e.539108",
"name": "",
"kind": "fcnt",
"count": "",
"initial": "",
"step": "1",
"condition": "",
"conditionType": "js",
"when": "before",
"enumeration": "enum",
"enumerationType": "msg",
"limit": "",
"loopPayload": "loop-index",
"finalPayload": "final-last",
"x": 630,
"y": 180,
"wires": [
[
"0a7d2f8b690e2662"
],
[
"0a7d2f8b690e2662"
]
]
},
{
"id": "0a7d2f8b690e2662",
"type": "function",
"z": "3c5de79e.539108",
"name": "getname",
"func": "var lampLocation = {\n payload:{\n name: msg.payload.LP_NUM,\n north: msg.payload.LP_NORTH,\n east: msg.payload.LP_EAST,\n gl: msg.payload.LP_GL,\n lat: msg.payload.LP_LAT,\n lon: msg.payload.LP_LONG,\n }\n};\n\nflow.set('lampLocation', lampLocation.payload);\n\nreturn lampLocation;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 880,
"y": 180,
"wires": [
[
"f6e5883a426a47ee"
]
]
},
{
"id": "f6e5883a426a47ee",
"type": "debug",
"z": "3c5de79e.539108",
"name": "check getLocation",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 910,
"y": 280,
"wires": []
},
{
"id": "fc28f3aa6bf7f897",
"type": "http request",
"z": "3c5de79e.539108",
"name": "",
"method": "GET",
"ret": "obj",
"paytoqs": "ignore",
"url": "https://www.hko.gov.hk/common/hko_data/R3/files/smart_lamppost_met_device_location.json",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 330,
"y": 580,
"wires": [
[
"66a9628cfafd3360"
]
]
},
{
"id": "66a9628cfafd3360",
"type": "split",
"z": "3c5de79e.539108",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 510,
"y": 580,
"wires": [
[
"bceabcb6ef9c199e",
"b9fa71faa1beab3c"
]
]
},
{
"id": "bceabcb6ef9c199e",
"type": "loop",
"z": "3c5de79e.539108",
"name": "",
"kind": "fcnt",
"count": "",
"initial": "",
"step": "1",
"condition": "",
"conditionType": "js",
"when": "before",
"enumeration": "enum",
"enumerationType": "msg",
"limit": "",
"loopPayload": "loop-index",
"finalPayload": "final-last",
"x": 730,
"y": 580,
"wires": [
[
"9bbe6f75b3d0e07c"
],
[
"9bbe6f75b3d0e07c"
]
]
},
{
"id": "b9fa71faa1beab3c",
"type": "debug",
"z": "3c5de79e.539108",
"name": "check lamp type object",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 510,
"y": 500,
"wires": []
},
{
"id": "9bbe6f75b3d0e07c",
"type": "function",
"z": "3c5de79e.539108",
"name": "getIDType",
"func": "return {\n payload: {\n lamppost_id: msg.payload.LP_NUMBER,\n lamppost_type: msg.payload.LP_TYPE,\n lat: msg.payload.LP_LATITUDE,\n lon: msg.payload.LP_LONGITUDE\n }\n};",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 920,
"y": 580,
"wires": [
[
"44d012a392194a77",
"3390fbfd129e6e6c"
]
]
},
{
"id": "44d012a392194a77",
"type": "switch",
"z": "3c5de79e.539108",
"name": "getDeviceID",
"property": "payload.lamppost_type",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "01",
"vt": "str"
},
{
"t": "eq",
"v": "02",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 1130,
"y": 580,
"wires": [
[
"47645c984b40cd47"
],
[
"9a7105c941f5a1d0"
]
]
},
{
"id": "3390fbfd129e6e6c",
"type": "debug",
"z": "3c5de79e.539108",
"name": "check idtype",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 930,
"y": 500,
"wires": []
},
{
"id": "47645c984b40cd47",
"type": "function",
"z": "3c5de79e.539108",
"name": "getIDType",
"func": "return {\n payload: {\n lamppost_id: msg.payload.lamppost_id,\n lamppost_type: msg.payload.lamppost_type,\n lat: msg.payload.lat,\n lon: msg.payload.lon,\n device_id: \"01\"\n }\n};",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1320,
"y": 540,
"wires": [
[
"6d629b022f73577e",
"71402cdd2b25df5f"
]
]
},
{
"id": "9a7105c941f5a1d0",
"type": "function",
"z": "3c5de79e.539108",
"name": "getIDType",
"func": "return {\n payload: {\n lamppost_id: msg.payload.lamppost_id,\n lamppost_type: msg.payload.lamppost_type,\n lat: msg.payload.lat,\n lon: msg.payload.lon,\n device_id: \"04\"\n }\n};",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1320,
"y": 600,
"wires": [
[
"bf617086f0d43abc",
"71402cdd2b25df5f"
]
]
},
{
"id": "6d629b022f73577e",
"type": "debug",
"z": "3c5de79e.539108",
"name": "check deviceID01",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1250,
"y": 440,
"wires": []
},
{
"id": "71402cdd2b25df5f",
"type": "loop",
"z": "3c5de79e.539108",
"name": "",
"kind": "fcnt",
"count": "",
"initial": "",
"step": "1",
"condition": "",
"conditionType": "js",
"when": "before",
"enumeration": "enum",
"enumerationType": "msg",
"limit": "",
"loopPayload": "loop-index",
"finalPayload": "final-last",
"x": 1530,
"y": 560,
"wires": [
[
"e7c7f72a8a5e93e4"
],
[
"e7c7f72a8a5e93e4"
]
]
},
{
"id": "bf617086f0d43abc",
"type": "debug",
"z": "3c5de79e.539108",
"name": "check deviceID04",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1450,
"y": 700,
"wires": []
},
{
"id": "e7c7f72a8a5e93e4",
"type": "function",
"z": "3c5de79e.539108",
"name": "setRequestForAllData",
"func": "// @ts-nocheck\nvar msg ={\n method:'GET',\n url: 'https://data.weather.gov.hk/weatherAPI/smart-lamppost/smart-lamppost.php?pi=' + msg.payload.lamppost_id + '&di=' + msg.payload.device_id,\n};\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1760,
"y": 560,
"wires": [
[
"a58ee1054e651ddb"
]
]
},
{
"id": "a58ee1054e651ddb",
"type": "http request",
"z": "3c5de79e.539108",
"name": "",
"method": "use",
"ret": "obj",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"insecureHTTPParser": false,
"authType": "",
"senderr": false,
"headers": [],
"x": 1970,
"y": 560,
"wires": [
[
"c08569e42cc92766",
"41d9300f3bf28ae6"
]
]
},
{
"id": "c08569e42cc92766",
"type": "debug",
"z": "3c5de79e.539108",
"name": "check get request",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 2010,
"y": 640,
"wires": []
},
{
"id": "41d9300f3bf28ae6",
"type": "function",
"z": "3c5de79e.539108",
"name": "getPI",
"func": "var lampInfo = { \n payload: {\n PI: msg.payload.PI,\n humdity: msg.payload.BODY.HKO.RH,\n // temp:msg.payload.BODY.HKO.TO\n }\n};\nflow.set('lampInfo', lampInfo.payload);\n\nreturn lampInfo;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 2150,
"y": 560,
"wires": [
[
"438bb9b3f164358c"
]
]
},
{
"id": "438bb9b3f164358c",
"type": "debug",
"z": "3c5de79e.539108",
"name": "check getInfo",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 2280,
"y": 620,
"wires": []
}
]