XML header trips error

Hi there,

I have looked and have not found the answer to my problem.

Running NR (Current version: 13.4.0) inside HA, but this is not HA related.

I'm setting up the heating at my home we use Möhlenhoff Alpha units and they use a very specific xml.
Reading is not a problem but when I wnat to submit a change the system throws a 400 error.
After trial and error I found that the error lies in the xml header <?xml version="1.0" encoding="UTF-8" standalone="yes"?> I have tried 2 identical messages (with the header adjusted) and only when I use <?xml version="1.0" encoding="UTF-8"?> so witout the standalone="yes" bit.

I'm not that proficient yet to use function modules so I tried to following set up.

[{"id":"f9e05cfb07dc39ec","type":"inject","z":"69588d0ab0888635","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<?xml version=\"1.0\" encoding=\"UTF-8\"?> <Devices>   <Device>     <ID>Master1EV</ID>     <HEATAREA nr=\"1\">       <T_TARGET>16</T_TARGET>     </HEATAREA>   </Device> </Devices>","payloadType":"str","x":430,"y":720,"wires":[["cc26578f49972747","38dc09c7d7c3b387"]]},{"id":"cc26578f49972747","type":"http request","z":"69588d0ab0888635","name":"Set Changes","method":"POST","ret":"txt","paytoqs":"ignore","url":"10.10.10.64/data/changes.xml","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"Content-Type","keyValue":"","valueType":"application/xml","valueValue":""}],"x":610,"y":740,"wires":[["fedabfc0174a3e2e"]]},{"id":"fedabfc0174a3e2e","type":"debug","z":"69588d0ab0888635","name":"This works","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":810,"y":740,"wires":[]},{"id":"38dc09c7d7c3b387","type":"debug","z":"69588d0ab0888635","name":"Working XML (no \"standalone\")","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":700,"wires":[]}]

When I do this it's fine, but to do this I'll probably need to use a function module and just learning Java now so...(tips welcome)

So I tried the following which doesn't work due to the aforementioned " standalone ="yes" " bit

[{"id":"f1f561cc629a44e4","type":"inject","z":"69588d0ab0888635","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<?xml version=\"1.0\" encoding=\"UTF-8\"?><Devices> <Device> <ID>Master1EV</ID> <HEATAREA nr=\"1\"> <T_TARGET>16</T_TARGET> </HEATAREA> </Device> </Devices>","payloadType":"str","x":310,"y":860,"wires":[["dd6677f30c54fdda"]]},{"id":"dd6677f30c54fdda","type":"xml","z":"69588d0ab0888635","name":"","property":"payload","attr":"","chr":"","x":450,"y":860,"wires":[["80fadf8f129f6755"]]},{"id":"b37e5535aebe7b27","type":"http request","z":"69588d0ab0888635","name":"Set Changes","method":"POST","ret":"txt","paytoqs":"ignore","url":"10.10.10.64/data/changes.xml","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[{"keyType":"Content-Type","keyValue":"","valueType":"application/xml","valueValue":""}],"x":990,"y":860,"wires":[["b4af4e6796c25110"]]},{"id":"d95da73e7a3388ad","type":"xml","z":"69588d0ab0888635","name":"","property":"payload","attr":"","chr":"","x":810,"y":860,"wires":[["b37e5535aebe7b27","42f55eb5cce496c7"]]},{"id":"80fadf8f129f6755","type":"change","z":"69588d0ab0888635","name":"","rules":[{"t":"set","p":"payload.Devices.Device[0].ID[0]","pt":"msg","to":"heat_unit","tot":"global","dc":true},{"t":"set","p":"payload.Devices.Device[0].HEATAREA[0].T_TARGET","pt":"msg","to":"kast_set_temp","tot":"global"},{"t":"set","p":"contentType","pt":"msg","to":"application/xml","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":860,"wires":[["d95da73e7a3388ad"]]},{"id":"42f55eb5cce496c7","type":"debug","z":"69588d0ab0888635","name":"Fault tripping XML due to \"standalone = \"yes\" \"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1100,"y":920,"wires":[]},{"id":"b4af4e6796c25110","type":"debug","z":"69588d0ab0888635","name":"node-red added \"standalone\"lead to error","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1260,"y":860,"wires":[]}]

Since the Alpha has it's own Testool I uploaded both versions of the XML and it's the header that lead to faults.

So the big question is, how to get rid of just that pesky bit in the header?

@Sandmman

give me 2 mins...

@Sandmman

hopefully this helps

[{"id":"b37e5535aebe7b27","type":"http request","z":"2d7bf6e3.84c97a","name":"Set Changes","method":"POST","ret":"txt","paytoqs":"ignore","url":"10.10.10.64/data/changes.xml","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"headers":[{"keyType":"Content-Type","keyValue":"","valueType":"application/xml","valueValue":""}],"x":530,"y":820,"wires":[[]]},{"id":"a7a7881b86d11a52","type":"template","z":"2d7bf6e3.84c97a","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<whatever>\n    <here>{{payload}}</here>\n</whatever>","output":"str","x":320,"y":820,"wires":[["23aceca6281b0a66","b37e5535aebe7b27"]]},{"id":"0df9a687fe0f311b","type":"inject","z":"2d7bf6e3.84c97a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":820,"wires":[["a7a7881b86d11a52"]]},{"id":"23aceca6281b0a66","type":"debug","z":"2d7bf6e3.84c97a","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":420,"y":740,"wires":[]}]

the template node will output a payload - that will then be used as the BODY.
the template node can read msg properties from the incoming message

Or just remove the offending section.

[{"id":"5d96a3c0.0d346c","type":"xml","z":"20bb0f7f9fab47a8","name":"","property":"payload","attr":"","chr":"","x":610,"y":680,"wires":[["796c7d4b.3bb0d4"]]},{"id":"fd86b042.a9741","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"set","p":"payload.Devices.Device[0].ID[0]","pt":"msg","to":"heat_unit","tot":"global","dc":true},{"t":"set","p":"payload.Devices.Device[0].HEATAREA[0].T_TARGET","pt":"msg","to":"kast_set_temp","tot":"global"},{"t":"set","p":"contentType","pt":"msg","to":"application/xml","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":680,"wires":[["5d96a3c0.0d346c"]]},{"id":"796c7d4b.3bb0d4","type":"change","z":"20bb0f7f9fab47a8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":" standalone=\"yes\"","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":720,"wires":[["bfa7651a.75bbb","29d82a74.ac333e"]]},{"id":"55658913.b26e98","type":"xml","z":"20bb0f7f9fab47a8","name":"","property":"payload","attr":"","chr":"","x":250,"y":680,"wires":[["fd86b042.a9741"]]},{"id":"bfa7651a.75bbb","type":"debug","z":"20bb0f7f9fab47a8","name":"Fault tripping XML due to \"standalone = \"yes\" \"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":800,"y":780,"wires":[]},{"id":"29d82a74.ac333e","type":"http request","z":"20bb0f7f9fab47a8","name":"Set Changes","method":"POST","ret":"txt","paytoqs":"ignore","url":"10.10.10.64/data/changes.xml","tls":"","persist":false,"proxy":"","authType":"","x":790,"y":680,"wires":[["a2931602.9d04e"]]},{"id":"152c4274.00a4ce","type":"inject","z":"20bb0f7f9fab47a8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<?xml version=\"1.0\" encoding=\"UTF-8\"?><Devices> <Device> <ID>Master1EV</ID> <HEATAREA nr=\"1\"> <T_TARGET>16</T_TARGET> </HEATAREA> </Device> </Devices>","payloadType":"str","x":110,"y":680,"wires":[["55658913.b26e98"]]},{"id":"a2931602.9d04e","type":"debug","z":"20bb0f7f9fab47a8","name":"node-red added \"standalone\"lead to error","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1060,"y":680,"wires":[]}]

Thanks, it does what I want, never even looked at the template node.... :tada:

1 Like

This one stumped me....never considered looking at the JSON of the flow if the header would be populated there.... once again thanks! :balloon:

Glad you got it sorted!
The template node is an understated gem!

1 Like