jtara92101 Posted January 6, 2012 Posted January 6, 2012 I can't seem to run a program through the REST interface? What might I be doing wrong? I've written and tested a little set of programs to essentially create a discrete on/off for my cable box, which only has a power toggle. It uses the networking module to send a command to an iTach Ip2IR which has an emitter on the cable box. I've tested this on the administrative console, and it works as expected. My problem is that the REST interface just returns this: 404 My command is: http://10.0.1.5/rest/programs/8240On/runIf I am able to use the REST interface to get status, etc. I know I've used it in the past to do simple things like turn lights on and off. Clearly, I'm missing some detail on running programs. BTW, the program is in a folder (A/V), but that shouldn't matter, right? Because when you run programs from within a program, it doesn't need the folder path. Maybe I need to include the path if I'm calling it from REST? (No, that doesn't seem to be the case, because I just moved the program out of the folder, and I still have the same problem.) Edit: Apparently, you need to refer to programs using a hex code? I'm just guessing here. I listed my programs using the REST interface, and each has a hex ID. This seems to match the (sparing) documentation. This is horribly documented!
io_guy Posted January 6, 2012 Posted January 6, 2012 404 is Auth. You need to send user/pass with the command.
jtara92101 Posted January 6, 2012 Author Posted January 6, 2012 404 is Auth. You need to send user/pass with the command. How do I do that? Edit: OK, figured it out. I need this: http://userid:password@10.0.1.5/rest/pr ... 002e/runIf I programed it into my Roomie Remote on my iPad, and it works great! No more shutting off the cable box as a side-effect of starting the TV activity when the cable box is already on. (As when Roomie has been closed - I don't know why it doesn't remember state when it closes - it's reasonable to assume that if the remote closes, that everything is still the same when you start it back up...) Ah, I discovered another undocumented or poorly documented "feature" of the REST interface: apparently programs MUST be at the root level of the program folders, or they are not seen by the REST interface. If you list programs with REST, it only shows the programs in the root. Amazing how this stuff goes for years with no documentation...
Michel Kohanim Posted January 6, 2012 Posted January 6, 2012 Hi jtara92101, I am not sure which documents you were looking at so please do let us know so that we can update. Our latest WSDK does have everything you need to know about REST with optional parameters to show folders recursively or not. That's how ISY AJAX works and thus it must have been documented somewhere. Just need to figure out what you were looking at. Thanks and with kind regards, Michel
jtara92101 Posted January 7, 2012 Author Posted January 7, 2012 Apparently I was wrong: programs do NOT have to be in the root folder to run them from the REST API. I just moved them back into the A/V folder, and they still work. You do need to use the recursive option to LIST them, however. I was looking at the Wiki documentation. I was unaware that there was any additional documentation. The Wiki documentation on REST is very thin. Where do I get the WSDK?
LeeG Posted January 7, 2012 Posted January 7, 2012 "Where do I get the WSDK?" Use this link to see the 3.1.16 announce. There is a link to the WSDK toward the bottom of the post. viewtopic.php?f=25&t=6015
oceanman93 Posted February 18, 2012 Posted February 18, 2012 I struggled some with the REST documentation. It would be really helpful to those who don't have a complete understanding if there were some complete examples. I know that there are a wide variety but this is what I had to do to understand all of the nuances of REST. I compiled my own "complete REST output" word doc which shows each REST command, the complete command that I used, the output for each and every syntax variety. Now I just go back and refer to that document when I can't remember something. It took me a little bit of time but time well spent. I hope this helps out others where I previously had struggled. Here are some examples. Note that I am using Mac OSX commands instead of a browser but the syntax is the same for the REST command piece. The unix "curl" command allows specifying user credentials using "-u" option; -u/--user , Specify the user name and password to use for server authentication. The "-s" option tells it to be silent with curl program output; -s/--silent, Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute. curl -u myuser:mypassword -s http://192.168.15.152:5052/rest/nodes <-- RETURNS ALL NODES (QUITE A LONG LIST IN MY CASE) curl -u myuser:mypassword -s http://192.168.15.152:5052/rest/status <-- RETURNS ALL NODES STATUS (AGAIN QUITE LONG) curl -u myuser:mypassword -s http://192.168.15.152:5052/rest/nodes/scenes <-- RETURNS ALL SCENES (THIS IS IMPORTANT TO FIND OUT SCENE NUMBER NEEDED TO ADDRESS A SINGLE SCENE) curl -u myuser:mypassword -s http://192.168.15.152:5052/rest/var/definitions/2 <-- RETURNS ALL STATE VARIABLE DEFINITIONS (USE 1 AT THE END FOR INTEGER VARIABLES curl -u myuser:mypassword -s http://192.168.15.152:5052/rest/programs <-- RETURNS ALL PROGRAMS AND DISPLAYS THE PROGRAM ID USED IN OTHER COMMANDS curl -u myuser:mypassword -s http://192.168.15.152:5052/rest/config <-- RETURNS CONFIG OUTPUT curl -u myuser:mypassword -s http://192.168.15.152:5052/rest/networking/resources <-- RETURNS ALL NETWORKING RESOURCES The next hard part is trying to pick out the relevant info that you want (parsing the response) since a lot of information can be returned for a single command. It takes some understanding and in my case, lots of trial and error to isolate the exact characters I wanted. I'll run these statements manually until I have what I desire at which point I can then use this output in a script. Here are more commands that I use. To utilize a device, the device ID is used and the dots (.) are replace with %20 and appended with %20 and subID. In the case of the thermostat temperature, this is a one (1). These statements assign the thermostat temperature readings and set points to local variables in a shell script. The cut arguments zero in on the information that I want. The "ST" is for status, "CLISPH" is for heating set point. I HAD TO PUT A SPACE AFTER THE http COMMAND IN ORDER FOR IT NOT TO BE ABBREVIATED BY THIS FORUM, THE COMMAND DOES NOT HAVE A SPACE AFTER http IN ORDER TO WORK PROPERLY # get Thermostat temps/setpoints # firstthermtemp=`curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/nodes/11%20BE%2042%201/ST 2> /dev/null | cut -f6 -d' '| cut -c12-13` firstthermset=`curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/nodes/11%20BE%2042%201/CLISPH 2> /dev/null | cut -f6 -d' '| cut -c12-13` secondthermtemp=`curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/nodes/11%20B4%2069%201/ST 2> /dev/null | cut -f6 -d' '| cut -c12-13` secondthermset=`curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/nodes/11%20B4%2069%201/CLISPH 2> /dev/null | cut -f6 -d' '| cut -c12-13` # These statements assign these local variable values back into ISY variables (only if they have changed from previous values so as to not overwhelm ISY) to be used by other programs: # if [ "$firstthermtemp" -ne "$lastfirstthermtemp" ] then curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/vars/set/2/15/$firstthermtemp 1> /dev/null echo "1st temp $firstthermtemp " #DISPLAY THE TEMP TO THE SCREEN, ALTERNATIVELY, MY UPDATED SCRIPT JUST ANNOUNCES IT! (kind of like the lotto commercial): say -v vicki "first floor temperature now $firstthermtemp " lastfirstthermtemp=$firstthermtemp fi if [ "$firstthermset" -ne "$lastfirstthermset" ] then curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/vars/set/2/16/$firstthermset 1> /dev/null lastfirstthermset=$firstthermset echo "1st set $firstthermset " fi if [ "$secondthermtemp" -ne "$lastsecondthermtemp" ] then curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/vars/set/2/17/$secondthermtemp 1> /dev/null lastsecondthermtemp=$secondthermtemp echo "2nd temp $secondthermtemp " fi if [ "$secondthermset" -ne "$lastsecondthermset" ] then curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/vars/set/2/18/$secondthermset 1> /dev/null lastsecondthermset=$secondthermset echo "2nd set $secondthermset " fi These commands turn off /on the scene number 63065 which includes the Living Room Corner Lamp. As you can see, the response is received and displayed unless it is otherwise suppressed. I HAD TO PUT A SPACE AFTER THE http COMMAND IN ORDER FOR IT NOT TO BE ABBREVIATED BY THIS FORUM, THE COMMAND DOES NOT HAVE A SPACE AFTER http IN ORDER TO WORK PROPERLY $ curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/nodes/63065/cmd/DON <?xml version="1.0" encoding="UTF-8"?>200 $ curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/nodes/63065/cmd/DOF <?xml version="1.0" encoding="UTF-8"?>200 These commands return & run a program number 004C which is Flash corner lamp. Valid commands for programs are the following (from ISY doc): pgm-cmd: run|runThen|runElse|stop|enable|disable|enableRunAtStartup| disableRunAtStartup
'runIf' is supported as well, but 'run' should be used instead. $ curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/programs/004C <?xml version="1.0" encoding="UTF-8"?>Flash corner lamp2012/02/16 11:24:492012/02/16 11:24:52 $ curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/programs/004C/runThen <?xml version="1.0" encoding="UTF-8"?>200 To get a variable value, variable type (2 state) variable ID (number 16) $ curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/vars/get/2/16 <?xml version="1.0" encoding="UTF-8"?>0020120213 14:58:59 $ curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/vars/get/2/15 <-- MY ASSIGNED THERMOSTAT SETTING FROM ABOVE <?xml version="1.0" encoding="UTF-8"?>676720120216 11:13:37 $ curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/vars/get/2/2 <-- MY KEGERATOR TEMPERATURE <?xml version="1.0" encoding="UTF-8"?>373720120216 11:28:51 To get a network resource executed, ID=2 for GC_YAMAHA_ON (turn stereo on though Global Cache IR command) $ curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/networking/resources/2 <?xml version="1.0" encoding="UTF-8"?>200 to name a few. Good luck!
GDavis01 Posted March 17, 2012 Posted March 17, 2012 oceanman93, Thanks for this post... I was trying to follow your other post "ISY has a Voice!" and in trying to better understand the REST commands I stumbed onto this one. This is really helpful. You mention that you compiled a "complete REST output" word doc... would you consider sharing the doc file? A couple of points: - In your post you have curl -u myuser:mypassword -s http://192.168.15.152:5052/rest/var/definitions/2 <-- RETURNS ALL STATE VARIABLE DEFINITIONS (USE 1 AT THE END FOR INTEGER VARIABLES I think that the correct syntax should be http://192.168.15.152:5052/rest/vars/definitions/2 - In the section where you show examples like this: $ curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/nodes/63065/cmd/DON<?xml version="1.0" encoding="UTF-8"?>200 I believe that there should be a space between the "8" and the "?" in <?xml version="1.0" encoding="UTF-8"?>. I raise this only because when parsing this if one is using the spaces as the delimiter there is one missing. This post has really helped my understanding... thanks again.
oceanman93 Posted March 20, 2012 Posted March 20, 2012 oceanman93, Thanks for this post... I was trying to follow your other post "ISY has a Voice!" and in trying to better understand the REST commands I stumbed onto this one. This is really helpful. You mention that you compiled a "complete REST output" word doc... would you consider sharing the doc file? A couple of points: - In your post you have curl -u myuser:mypassword -s http://192.168.15.152:5052/rest/var/definitions/2 <-- RETURNS ALL STATE VARIABLE DEFINITIONS (USE 1 AT THE END FOR INTEGER VARIABLES I think that the correct syntax should be http://192.168.15.152:5052/rest/vars/definitions/2 - In the section where you show examples like this: $ curl -u myuser:mypassword -s http ://192.168.15.152:5052/rest/nodes/63065/cmd/DON<?xml version="1.0" encoding="UTF-8"?>200 I believe that there should be a space between the "8" and the "?" in <?xml version="1.0" encoding="UTF-8"?>. I raise this only because when parsing this if one is using the spaces as the delimiter there is one missing. This post has really helped my understanding... thanks again. Sorry for the typo. I try so hard to copy and paste things as I do them instead of retyping but sometimes in my haste I make a typo. So yes, the command should use "vars" instead of "var". I reran the scene command and the returned text is the following straight copied from my terminal window, I don't see a space: <?xml version="1.0" encoding="UTF-8"?>200 My compiled document is merely all of my executed commands so I can refer back to my own syntax and things learned. That's what I shared, a bunch of my examples because it took me so long to figure out all of the details I thought that there's got to be someone else out there with my same pain. I'll go through it and put a few more examples if there are any that are different from what I've already posted. Glad it all helped you out.
GDavis01 Posted March 23, 2012 Posted March 23, 2012 Interesting!! When I was trying to figure out the how to parse the output I was using my PC with the following command in explorer: http://192.168.1.198/rest/vars/get/2/13 Here was the output: <?xml version="1.0" encoding="UTF-8" ?> - 6 6 20120323 06:19:54 Note the extra space in ="UTF-8" ? When I used the same command on the iMac in Safari here is what I got: 6620120323 06:19:54 Now I just tried the curl command in terminal and I see the correct output, without that space! Now the cut command makes more sense (I also realized that I was using it incorrectly!). Thanks again...
arw01 Posted February 17, 2013 Posted February 17, 2013 Could the admin team edit oceans post to fix var to vars in the definition call?
Recommended Posts