NR http request

I'm trying to call a http put in response to the states of a switch in hubitat but can't get it to work. This is to switch the scene on a Hikvision camera based on the virtual switch which will be operated by lux level from an existing sensor. The url is:

http://IP_Address:http_port/ISAPI/Image/channels/1/mountingScenario/

and I need to send the following xml in the body:

<?xml version="1.0" encoding="UTF-8"?>
<MountingScenario version="2.0" xmlns="http://www.hikvision.com/ver20/XMLSchema">
    <mode>lowIllumination</mode>
</MountingScenario>

I have the flow as shown below and can see the status of the switch changing but that's about it:

Any ideas how to get this working. I'm guessing I've got the http request node incorrectly setup:


Are you expecting the text in the "Description" box to be sent? I don't think it works that way - the description box is for documentation.

You would need to put the xml in msg.headers and give that as an input to the http request node. I do something similar for logging into my HE hub from Node-RED where I send the cookies info by building msg.headers in a Function node.

var cookies = msg.responseCookies;
msg.headers = {
    Cookie : "HUBSESSION=" + cookies.HUBSESSION.value,
    'content-type':'application/x-www-form-urlencoded'};

//Hubitat login username and password for form data
var data = 'username='+msg.username+'&password='+msg.password+'&submit=Login';
msg.payload = data;
return msg;

Hope this helps.

I wondered about that - thanks. I'm messing around with adding headers but not really getting anywhere. I've tried adding 'Accept' with 'application/xml' and then 'msg' with the xml from the first post but that doesn't seem to work either.

The easiest way to figure out what is going on is to use a utility to watch the http traffic. (I use Proxyman on the Mac). Then if you go to the website using just your regular browser, you can see the format and content of what it is being sent and format your input from the http request node appropriately.

Nothing showing in Proxyman when I trigger the switch and the put should be sent. I think I'm fighting a losing battle. I can enter the url and xml in postman and it works but I can do nothing with Hubitat or node-red

Looks like my last reply got deleted when this was split into its own thread!

@johnwill1 Can you DM me what you are sending in Postman and your flow?

@rakeshg Thanks - I can just pop it here there's nothing sensitive in there.

This is what goes in postman to change the scene in the camera to 'normal':


Since your last message I did manage to get some information from Proxyman but it's possibly just created another hurdle for sending this command outside of postman. I can see that the initial request gets a 401 unauthorised, then postman retries after amending the request and that works. If I "disable retrying the request" it will just fail. You can see this below:


It may be that I need to use https perhaps. Regardless I need to be able to test sending something in postman that works first time without the need for that app to rewrite the request based on the initial response.

In your Proxyman screen, can you select "Header"? It looks like you have selected "Raw", so I'm not what format the header is in.

In order to get around the initial request being denied, I've temporarily enabled Basic authentication in the camera and added the details to the url. So it's now:

http://user:password@192.168.0.111/ISAPI/Image/channels/1/mountingScenario/

That works without any errors in postman. So I'm just stuck on how to send that in node-red

So no cookies, session ID etc. being passed in? Your http request node looks a little different than mine (I'm still on Node-RED v2.2.2) but what happens if you enter the user name/password node parameters?

With postman I can set the username and password in the authentication field or directly in the url and it'll switch the scene using the xml. So it should work the same in node-red. However when I activate the switch in Hubitat that should send the http request; although the device node in the flow updates to 'on' or 'off', I don't see anything in corresponding events in Proxyman to show anything is sent.

Can you test the flow by using an inject node? Create two inject nodes, disable the HE node. and set msg.payload in the inject node to “on” for one and “off” for the other and connect them to the appropriate http request node. If that doesn’t trigger the flow, there is something else going on.

@rakeshg I think I've made progress using a different node - I'm obviously getting nowhere with the http request node.

I've downloaded the 'Hikvision Ultimate' palette which contains an XML node. With that I can create a connection to the camera using the user credentials with either Basic or Digest authentication specified. Once connected I've just pasted the xml in and it worked first time.

1 Like

Great! And the switch triggers it as well?

1 Like

Yeah I'm just messing with it now as I had it linked to another device. I've also been using a standalone camera connected directly to the LAN rather via the NVR, so I'll change things one at a time and set teh security back to Digest.

The idea is that I'll have a rule that triggers when external luminance passes a particular threshold that turns on/off the virtual switch (I do this for my external lighting rather than using sunrise/sunset with offsets). In NR that goes to a switch node and the two outputs for on/off will (hopefully) switch the mode to Low Illumination and back to Normal again.

1 Like

I do something like this to turn on two different sets of indoor lamps based on lux reading but all my "rules" are in Node-RED.

It looks as though I've had a few different problems here. I've created a virtual switch, exposed it to node-red in maker api and using the device node, I can see that device switching between on and off in the node-red flow. 'Send events' is checked. However the xml node will simply not trigger from that node - not a clue why. However if I connect the xml node to one of my devices in another flow - it all works normally. I'm baffled

Very strange - if you put a debug node connected to the device node, do you see anything? Also, I'm assuming you created this as a virtual "switch" (on/off)?

1 Like

Finally got it working, probably about 24 hours since I first started messing around (talk about a wasted 53rd birthday!)

The switch node was incorrectly figured. I needed to use a debug node to find the correct path. Initially I was incorrectly looking at the property message.payload for ==on and ==off

What I needed to do was set it to message.payload.value ==on and ==off

1 Like

Thats where I was going wrong. The output wasn't as expected

1 Like