Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| indigo_s_restful_urls [2015/07/13 15:32] – jay | indigo_s_restful_urls [2026/04/07 18:27] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Indigo REST API ====== | ||
| + | <color red> | ||
| + | |||
| + | These REST semantics are loosely based [[http:// | ||
| + | |||
| + | ===== Devices Access ===== | ||
| + | Examples to get HTML, JSON (new in Indigo 6), XML, and TXT versions of the device list: | ||
| + | < | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Examples to get HTML, XML, and TXT versions of device " | ||
| + | < | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example of editing using HTML form to modify office-lamp editable properties; Form submit will do a virtual PUT to update the properties: | ||
| + | < | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example use of curl and virtual HTTP PUT call to change brightness to 27; HTTP result is a 303 redirect back to the device resource after the update is complete: | ||
| + | < | ||
| + | curl -X PUT -d brightness=27 http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example use of curl and virtual HTTP PUT call to change office-lamp' | ||
| + | < | ||
| + | curl -X PUT -d isOn=0 http:// | ||
| + | curl -X PUT -d isOn=1 http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example use of curl and virtual HTTP PUT call to toggle office-lamp' | ||
| + | < | ||
| + | curl -X PUT -d toggle=1 http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example use of curl and virtual HTTP PUT call to change speedIndex to 0 (off), 3 (high), then decrease back to 0 (off): | ||
| + | < | ||
| + | curl -X PUT -d speedIndex=0 http:// | ||
| + | curl -X PUT -d speedIndex=3 http:// | ||
| + | curl -X PUT -d speedIndex=dn http:// | ||
| + | curl -X PUT -d speedIndex=dn http:// | ||
| + | curl -X PUT -d speedIndex=dn http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example use of curl and virtual HTTP PUT call to change device " | ||
| + | < | ||
| + | curl -X PUT -d activeZone=3 http:// | ||
| + | curl -X PUT -d activeZone=0 http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example use of curl and virtual HTTP PUT call to change device " | ||
| + | < | ||
| + | curl -X PUT -d activeZone=stop http:// | ||
| + | curl -X PUT -d activeZone=run http:// | ||
| + | curl -X PUT -d activeZone=pause http:// | ||
| + | curl -X PUT -d activeZone=resume http:// | ||
| + | curl -X PUT -d activeZone=next http:// | ||
| + | curl -X PUT -d activeZone=prev http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example use of curl and virtual HTTP PUT call to change device " | ||
| + | < | ||
| + | curl -X PUT -d setpointCool=68 -d setpointHeat=84 http:// | ||
| + | curl -X PUT -d setpointCool=72 -d setpointHeat=78 http:// | ||
| + | curl -X PUT -d setpointCool=up -d setpointHeat=up http:// | ||
| + | curl -X PUT -d setpointCool=dn -d setpointHeat=dn http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example use of curl and virtual HTTP PUT call to change device " | ||
| + | < | ||
| + | curl -X PUT -d hvacCurrentMode=" | ||
| + | curl -X PUT -d hvacCurrentMode=" | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example use of curl and virtual HTTP PUT call to change device " | ||
| + | < | ||
| + | curl -X PUT -d hvacFanMode=" | ||
| + | curl -X PUT -d hvacFanMode=" | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example use of curl and virtual HTTP PUT call to change binary output state of an EZIO module device " | ||
| + | < | ||
| + | curl -X PUT -d outputBinaryStates=" | ||
| + | curl -X PUT -d outputBinaryStates=" | ||
| + | curl -X PUT -d outputBinaryStates=" | ||
| + | curl -X PUT -d outputBinaryStates=" | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | ===== Variable Access ===== | ||
| + | Examples to get HTML, JSON (new in Indigo 6), XML, and TXT versions of the variable list: | ||
| + | < | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Examples to get HTML, JSON (new in Indigo 6), XML, and TXT versions of variable " | ||
| + | < | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example use of curl and virtual HTTP PUT call to change variable " | ||
| + | < | ||
| + | curl -X PUT -d value=1.23 http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | And, while not exactly RESTful, here's the URL you can use in your custom control pages to link to an editor page for a variable (select "Link to External URL" on the " | ||
| + | |||
| + | < | ||
| + | |||
| + | That replaces the variable plugin that's in the user contribution library. | ||
| + | |||
| + | ===== Action Group Access and Execution ===== | ||
| + | Examples to get HTML, JSON (new in Indigo 6), XML, and TXT versions of the action group list: | ||
| + | < | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Examples to get HTML, JSON (new in Indigo 6), XML, and TXT versions of action group " | ||
| + | < | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example use of curl and virtual HTTP execute call to execute action group "party scene": | ||
| + | < | ||
| + | curl -X EXECUTE http:// | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | ===== INSTEON Links Retrieval ===== | ||
| + | Example to get XML version (HTML, JSON and TXT not available) of the INSTEON links: | ||
| + | < | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example to get XML INSTEON links for device " | ||
| + | < | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | Example to get XML INSTEON links for the PowerLinc: | ||
| + | < | ||
| + | http:// | ||
| + | </ | ||
| + | |||
| + | ===== Authentication ===== | ||
| + | As of v2021.1, Indigo now supports both basic and digest HTTP authentication simultaneously, | ||
| + | |||
| + | ===== HTTP Authentication ===== | ||
| + | **HTTP Digest** authentication is the default authentication method for the REST API. To use it in the curl examples above, you can specify your authentication like this: | ||
| + | |||
| + | < | ||
| + | |||
| + | In Python, we recommend using the [[https:// | ||
| + | |||
| + | < | ||
| + | from requests.auth import HTTPDigestAuth | ||
| + | reply = requests.get(' | ||
| + | </ | ||
| + | |||
| + | Of course, you would use the full REST URL. That will allow your scripts to successfully authenticate and execute against a protected server. | ||
| + | |||
| + | If you have **HTTP Basic** authentication enabled in the Start Local Server dialog, you can pass the username and password on the URL itself (note that this is less secure and should only be used on HTTPS connections since the password is sent in clear text on non-HTTPS URLs): | ||
| + | |||
| + | https:// | ||
| + | |||
| + | We don't enable Basic auth by default because it is less secure than Digest auth, but we make it available when you have no other option to integrate from an outside source. | ||
| + | |||
| + | ===== API Key ===== | ||
| + | In Indigo 2021.1 or later, you can use an even more secure API token to authenticate your REST requests. | ||
| + | |||
| + | <color blue> | ||
| + | |||
| + | To use keys to authenticate REST calls, you must first generate an API Key in your Indigo Account. Log in and select the Authorizations item in the navigation menu on the left. This will show you a page that looks something like this: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | The lower section of the page shows your API Keys. You can generate a new key by selecting your license from the popup at the bottom and clicking the Add API Key button. This will generate a key that is valid on the license specified (most users just have a single license, but some have multiple). | ||
| + | |||
| + | Next, when you make a call to the REST API, you will include the Authorization header with the value of ' | ||
| + | |||
| + | < | ||
| + | |||
| + | In Python: | ||
| + | |||
| + | < | ||
| + | my_headers = {" | ||
| + | reply = requests.get(' | ||
| + | </ | ||
| + | |||
| + | Again, you would use the full REST URL rather than just the host. | ||
| + | |||
| + | ===== AppleScript & the RESTful API ===== | ||
| + | To work around the Mac OS X " | ||
| + | |||
| + | For example, here's a simple AppleScript that will turn an Indigo device ON and then OFF: | ||
| + | |||
| + | < | ||
| + | set indigoServerIPandPort to " | ||
| + | set indigoServerUsername to " | ||
| + | set indigoServerPassword to " | ||
| + | set devName to " | ||
| + | set turnOffCommand to "curl -u " & indigoServerUsername & ":" | ||
| + | set turnOnCommand to "curl -u " & indigoServerUsername & ":" | ||
| + | do shell script turnOnCommand | ||
| + | do shell script turnOffCommand | ||
| + | </ | ||
| + | |||
| + | And here's a simple AppleScript that will set the value of an Indigo variable: | ||
| + | |||
| + | < | ||
| + | set indigoServerIPandPort to " | ||
| + | set indigoServerUsername to " | ||
| + | set indigoServerPassword to " | ||
| + | set varName to " | ||
| + | set varValue to " | ||
| + | set commandString to "curl -u " & indigoServerUsername & ":" | ||
| + | do shell script commandString | ||
| + | </ | ||
| + | |||
| + | Here's an example of getting a variable value: | ||
| + | |||
| + | < | ||
| + | set varValueJson to do shell script "curl -u username: | ||
| + | |||
| + | tell application "JSON Helper" | ||
| + | set varValueRecord to read JSON from varValueJson | ||
| + | set varValue to value of varValueRecord | ||
| + | end tell | ||
| + | </ | ||
| + | |||
| + | Note, to use this script you need the Mac App called [[https:// | ||
| + | |||
| + | This approach has the advantage of running from any Mac anywhere, whether on the same Mac as your server, another Mac on your local network, or a Mac somewhere out on the internet (use your reflector URL if you're doing the latter). | ||
| + | |||
| + | You can also have AppleScript directly communicate with Indigo' | ||