With the correct username and password before the IP address, that works great with curl. When I tried to do this using Rule Machine, it wasn't working for me. I put the XML content in the body, but after I click outside that box, the XML tags disappear, and I'm left with 40971. The XML body should be:
I tried adding some backslashes to escape some of the characters, and it seemed to do something to some of the xml tags, but not all of them. Has anyone used Rule Machine to POST XML?
My only problem is that now the 'body for POST' field is correct, then it again gets interpreted, resulting in the wrong message. I think I'm going to have to escape the ampersands, which will then get changed in the body text, which will then get interpreted:
Here I entered: <?xml version="1.0" encoding="utf-8"?><request><ptzcmd><cmd>4097</cmd><preset><index>1</index></preset></ptzcmd></request>
That last option should do it, but I tried this and it didn't work for me. I even tried escaping the ampersands a second time, so that the POST contained escaped < and > characters, but that didn't fix it.
I'm not sure how Rule Machine sets up the POST, and if double quotes are an issue as well. It's worth a try.
I can do it straight from curl on my Ubuntu 18.04 laptop, but I'm not sure why Rule Machine isn't managing it. Maybe I'll need to do it from a custom driver, or see if I can get the camera to accept JSON. I pulled the XML from the javascript used in the IP camera's web interface, but maybe it will accept JSON input also. It's worth a shot I guess. I really would like to control camera presets from Hubitat.
When doing http sends in Groovy a urlencode command is usually done prior to sending. No idea how to do a urlencode in RM
Update
Forgot to mention the Hub's API generally does not accept, as in trashes, HTML like data strings. Also your initial HTMLeconded string does not work when sending as a URL.
A while back I wanted to send some SSML for a TTS arming countdown and encountered this issue. I ended up changing <> to {} for the external data string, then changing {} back to <> with Groovy code prior to sending the message. If you can do the character conversion with RM, it's another approach.
Example: {speak}Alarm system is arming in 30 seconds, please exit the facility. {break time="1s"/} 25 seconds{break time="2800ms"/}20 seconds{break time="2800ms"/}15 seconds{break time="2800ms"/}10 seconds{break time="2800ms"/}5{break time="700ms"/}4{break time="700ms"/}3{break time="700ms"/}2{break time="700ms"/}1{/speak}
If you can code or want to try coding Groovy, here is a urlencode example from my SmartUPS module sending a command to Windows Event Ghost from the Hub
Looks good, I might try to hack that and get it to work. I'm no developer but I can usually get things to work by hacking what others have done.
I'll definitely keep trying for a bit until I can control my cameras from HE. I can think of lots of uses for that, such as zooming to a preset based on motion detectors.
I think I'll try URL encoding with single quotes instead of double quotes. I can also try HTML encoding that way. It's worth a try once I get home from work.
Using a simple RM to Speak a message I did a bit of testing to refresh my memory.
Attempting to enter text <hello/><goodbye/> always results in an empty text field
URLencoded text was accepted, but the system placed single quotes around the text. Unfortunately it spoke all the control characters letters and numbers.
I feel support's assistance is needed for your HTTP XML issue.
Obviously, we didn't set it up to support XML. I'll look into that possibility. It isn't really setup to support URL Encoding either, and that will be looked at as well. These should probably just be explicitly usable.
OK, thanks. I was wondering if I was missing something about how I was entering the XML text. I'd guess you could remove the xml content-type option until that can be fixed.
Also, I'm not sure if Select content type: xml means text/xml or application/xml. Either one would work for me, but maybe someone would care one way or the other. I actually got it to work using "Content-Type: text/plain" from curl as well, but still couldn't get the HTTP POST to work from HE using the text option (and it again interpreted the text, so it needed to be encoded in the text entry box).
I may try to get this working as a custom driver in the meantime.
Well, for now, I have a custom driver that does this, thanks to @arnb and some web searches.
This will be great to integrate with my security cams so I can choose preset locations. I'd like to have my PTZ cameras zoom to specific preset locations based on PIR sensors. Should be easy to do now.