I've got a nagging issue with a msg property not persisting after being passed to the next node.
My scenario is grabbing a Stripe payment web-hook...
I get the web-hook with much needed metadata attached coming in fine into the http endpoint.
I try to assign the metadata to msg.meta
like so : msg.meta = msg.payload.data.object.metadata;
.
I see the debug output proper values after the first function node gets the data and assigns it to msg.meta
.
The odd thing is that by the next node (even without modifying or anything) this reference msg.meta
value is empty. Something is doing something somewhere to this value, and It won't stick... Odd part as well is that I even JSON.parse(JSON.stringify(msg.payload.data.object.metadata));
as supposedly it makes a 'copy' of the object without referencing it.
I checked all the nodes extensively and don't see anything obvious what can cause this.
I will include the flow JSON if you want to look for yourselves.
[
{
"id": "11562560.1aab2b",
"type": "mongodb out",
"z": "d04ea5a4.8bc1e8",
"mongodb": "8f55ecde.6f0a8",
"name": "",
"collection": "subscriptions",
"payonly": true,
"upsert": false,
"multi": false,
"operation": "store",
"x": 3840,
"y": 320,
"wires": []
},
{
"id": "7c7d69ef.4c1b68",
"type": "function",
"z": "d04ea5a4.8bc1e8",
"name": "AFTER CONFIRMATION : LOAD DATABASE WITH ACTIVE SUBSCRIPTION DATA",
"func": "//payload will be a subscriber active object // with a timestamp to measure a duration\n\nlet out = {};\n\n\nout = {\n \"keywords\" : [],\n \"userid\" : msg.meta.userid,\n // \"receipt_url\" : msg.payload.data.object.receipt_url,\n \"start_date\" : new Date(),\n //\"expires\" : Date() ,\n // \"active\" : true,\n // \"keywords_are_set\" : true,\n \"pref\" : {\n \"alerts_enabled\" : {\n \"email\" : false,\n \"sms\" : false,\n }\n }\n};\n\n\n// //Keyword Assignment to payload.\n\nif(msg.meta.keyword1){out.keywords.push(msg.meta.keyword1);}\nif(msg.meta.keyword2){out.keywords.push(msg.meta.keyword2);}\nif(msg.meta.keyword3){out.keywords.push(msg.meta.keyword3);}\nif(msg.meta.keyword4){out.keywords.push(msg.meta.keyword4);}\nif(msg.meta.keyword5){out.keywords.push(msg.meta.keyword5);}\nif(msg.meta.keyword6){out.keywords.push(msg.meta.keyword6);}\nif(msg.meta.keyword7){out.keywords.push(msg.meta.keyword7);}\nif(msg.meta.keyword8){out.keywords.push(msg.meta.keyword8);}\nif(msg.meta.keyword9){out.keywords.push(msg.meta.keyword9);}\nif(msg.meta.keyword10){out.keywords.push(msg.meta.keyword10);}\n\nmsg.payload = out;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 3130,
"y": 320,
"wires": [
[
"7c7c9739.2499f8",
"c4a8d1ae.710a5"
]
]
},
{
"id": "c4a8d1ae.710a5",
"type": "debug",
"z": "d04ea5a4.8bc1e8",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 3270,
"y": 180,
"wires": []
},
{
"id": "367234c5.dbb03c",
"type": "http response",
"z": "d04ea5a4.8bc1e8",
"name": "",
"statusCode": "",
"headers": {},
"x": 2890,
"y": 420,
"wires": []
},
{
"id": "1da5de6b.e66f52",
"type": "template",
"z": "d04ea5a4.8bc1e8",
"name": "Reply back to Stripe Webhook",
"field": "outbound",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "OK",
"output": "str",
"x": 2690,
"y": 420,
"wires": [
[
"367234c5.dbb03c"
]
]
},
{
"id": "851aee68.c99da",
"type": "comment",
"z": "d04ea5a4.8bc1e8",
"name": "STRIPE WEB-HOOK",
"info": "Checks if payment was successfull, assigns a \n\"tier\" and adds the \"subscription\" instance to \nthe database , \"subscriptions\" colleciton specifically,\n\nThe subscriptions will be used to store all \ninstances even if customer has multiple instances of say 10 keywords etc.",
"x": 2170,
"y": 240,
"wires": []
},
{
"id": "4fb15c83.c8e784",
"type": "http in",
"z": "d04ea5a4.8bc1e8",
"name": "",
"url": "/stripe-webhook",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 2180,
"y": 260,
"wires": [
[
"b072b86d.467548",
"1da5de6b.e66f52"
]
]
},
{
"id": "7c7c9739.2499f8",
"type": "function",
"z": "d04ea5a4.8bc1e8",
"name": "Set Target DB",
"func": "\nmsg.collection=\"subscriptions\";\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 3540,
"y": 320,
"wires": [
[
"11562560.1aab2b",
"c4a8d1ae.710a5"
]
]
},
{
"id": "b072b86d.467548",
"type": "function",
"z": "d04ea5a4.8bc1e8",
"name": "attache msg.meta data",
"func": "msg.meta = RED.util.cloneMessage(msg.payload.data.object.metadata);\n//msg.meta = JSON.parse(JSON.stringify(msg.payload.data.object.metadata));\n//msg.stripe_obj = JSON.parse(JSON.stringify(msg.payload.data.object));\n\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 2450,
"y": 260,
"wires": [
[
"6ce4cdd9.b42944",
"c4a8d1ae.710a5"
]
]
},
{
"id": "e26a24b2.17c318",
"type": "function",
"z": "d04ea5a4.8bc1e8",
"name": "CHECK FOR APPROVAL",
"func": "if(msg.payload.type == \"charge.succeeded\") {\n return [msg,null];\n}else{\n return [null, msg];\n}",
"outputs": 2,
"noerr": 0,
"x": 2850,
"y": 260,
"wires": [
[
"7c7d69ef.4c1b68"
],
[]
]
},
{
"id": "6ce4cdd9.b42944",
"type": "function",
"z": "d04ea5a4.8bc1e8",
"name": "",
"func": "\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 2650,
"y": 260,
"wires": [
[
"e26a24b2.17c318"
]
]
},
{
"id": "8f55ecde.6f0a8",
"type": "mongodb",
"z": "",
"hostname": "127.0.0.1",
"port": "27017",
"db": "carproj_db",
"name": ""
}
]
Hope someone out there can help...
UPDATE: I will be step-by-stepping through my debug process and try to update:
I have confirmed, that when all other debugs are off, except only attached to the endpoint HTTP POST node, I get two hook messages making it to the debugger. One with the metadata, and one without. I am suspecting this might be a Stripe thing sending another web-hook.
***Upon looking further I see Stripe is sending two Web-hooks one with the metadata and one confirming success of the charge (without the metadata)... This might be what I'm noticing when I check for "charge.succeeded", as my function checks and passes the message if it contains that, and ALL hooks with the that message have no metadata. Just now realized that. Will see if I can get results. Looking like a Stripe education lesson, instead of bug issues