Msg property not persisting

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 :slight_smile:

Seems to work for me - (with a dummy inject)

[{"id":"3217500b.19cdf","type":"debug","z":"3ead5d77.6a6672","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1610,"y":2320,"wires":[]},{"id":"eca68adf.2c0e08","type":"function","z":"3ead5d77.6a6672","name":"Set Target DB","func":"\nmsg.collection=\"subscriptions\";\n\nreturn msg;","outputs":1,"noerr":0,"x":1580,"y":2260,"wires":[["3217500b.19cdf"]]},{"id":"3b3fa143.990b7e","type":"function","z":"3ead5d77.6a6672","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":1170,"y":2260,"wires":[["eca68adf.2c0e08","c4c07494.441d38"]]},{"id":"78aa9228.2d037c","type":"function","z":"3ead5d77.6a6672","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":890,"y":2200,"wires":[["3b3fa143.990b7e","e35478e3.6de908"],["d466c1e8.1156"]]},{"id":"c4c07494.441d38","type":"debug","z":"3ead5d77.6a6672","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1550,"y":2200,"wires":[]},{"id":"82a7f0fc.25263","type":"function","z":"3ead5d77.6a6672","name":"","func":"\nreturn msg;","outputs":1,"noerr":0,"x":690,"y":2200,"wires":[["78aa9228.2d037c","563cdbfb.d83044"]]},{"id":"e35478e3.6de908","type":"debug","z":"3ead5d77.6a6672","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1110,"y":2180,"wires":[]},{"id":"d466c1e8.1156","type":"debug","z":"3ead5d77.6a6672","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1110,"y":2220,"wires":[]},{"id":"87defa6d.355428","type":"function","z":"3ead5d77.6a6672","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":490,"y":2200,"wires":[["a2010fc2.366ee","82a7f0fc.25263"]]},{"id":"563cdbfb.d83044","type":"debug","z":"3ead5d77.6a6672","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":890,"y":2140,"wires":[]},{"id":"a2010fc2.366ee","type":"debug","z":"3ead5d77.6a6672","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":710,"y":2120,"wires":[]},{"id":"5d26b1e0.14b2","type":"http in","z":"3ead5d77.6a6672","name":"","url":"/stripe-webhook","method":"post","upload":false,"swaggerDoc":"","x":220,"y":2200,"wires":[["6c922436.8a86ac","87defa6d.355428"]]},{"id":"cca38a1b.bd2a58","type":"inject","z":"3ead5d77.6a6672","name":"","topic":"","payload":"{\"data\":{\"object\":{\"metadata\":\"Hello\"}},\"type\":\"charge.succeeded\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":2300,"wires":[["87defa6d.355428"]]},{"id":"6c922436.8a86ac","type":"template","z":"3ead5d77.6a6672","name":"Reply back to Stripe Webhook","field":"outbound","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"OK","output":"str","x":530,"y":2300,"wires":[["d4689c9a.d894b"]]},{"id":"d4689c9a.d894b","type":"http response","z":"3ead5d77.6a6672","name":"","statusCode":"","headers":{},"x":750,"y":2300,"wires":[]}]

dceejay, thanks for the quick trial on my flow,

I too have copied an incoming Stripe web-hook msg into an injectable dummy message, and I don't get any issues. When I get test web-hooks from Stripe (as they will be played out in needed functionality), I find I get the repeated issues described. My msg.meta populated fields (cloned and/or original) seem to be able to populate within that first function node, and outputs to the debugger with the data I need, but once it's sent out, those values disappear within the next function node, sometimes with the next function node empty. Even the original Stripe populated object deep in the incoming payload.data.object.metadata , only the metadata oddly is cleared, and then left empty when it does change.

Not sure if you have a running Stripe test account where you can create (in my case a subscription)
and web-hook it to your node-red http in,
and pass it metadata : {"Submission ID":"82","Form ID":"4097","customer_email":"admin@radar-blip.com","customer_name":"admin","keyword1":"computers","tier":"1","userid":"1"}

Granted, my configuration and environment is not easily emulated.

I will be checking again with fresh eyes this morning, hopefully I can scope a culprit without wasting most of the day (again).. Will report back anything I find out pertaining to this issue.

If you give me a URL to a web-hook, maybe I can have some test web-hooks sent along to that as well...

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