| Both sides previous revision Previous revision Next revision | Previous revision |
| indigo_2022.2_documentation:rest_to_http_api_conversion_examples [2023/02/22 22:31] – jay | indigo_2022.2_documentation:rest_to_http_api_conversion_examples [2024/06/27 00:08] (current) – external edit 127.0.0.1 |
|---|
| | ====== REST API Conversion Examples ====== |
| | |
| | If you're using the old REST API (which has been deprecated), here are some examples of how you might convert your REST usages to the HTTP API. |
| | |
| | The first thing you'll want to understand is how to use [[api#authentication1|authentication with the HTTP API]]. The examples below use both headers and query args for authentication. You can use whichever works for you. You should replace ''YOUR-API-KEY'' with [[https://www.indigodomo.com/account/authorizations|your actual API Key]]. |
| | |
| | Second, all replies to the API will be [[api#api_messages|JSON messages]]. |
| | |
| | In the following examples, we'll be using a mix of authentication headers and the API Key as a query arg. You can use either. We mark the examples **REST** (old REST API) and **HTTP** (newer HTTP API). |
| | |
| | ===== Device Access ===== |
| | |
| | ==== Getting Devices ==== |
| | |
| | === get device list === |
| | |
| | == REST == |
| | <code>http://username:[email protected]:8176/devices.json</code> |
| | |
| | == HTTP == |
| | <code>http://127.0.0.1:8176/v2/api/indigo.devices?api-key=YOUR-API-KEY</code> |
| | |
| | This will return a JSON list of [[indigo_2022.2_documentation:api#device_objects|Device Objects]]. |
| | === get single device === |
| | |
| | == REST == |
| | <code>http://username:[email protected]:8176/devices/office-lamp.json</code> |
| | |
| | == HTTP == |
| | <code>http://127.0.0.1:8176/v2/api/indigo.devices/123456789?api-key=YOUR-API-KEY </code> |
| | |
| | Insert the ID of the ''office-lamp'' device rather than the name. Note you can quickly copy the device ID to the clipboard by right-clicking on the device in Indigo app's main window and choosing the ''Copy ID'' context menu. |
| | |
| | This will return a single [[indigo_2022.2_documentation:api#device_objects|Device Object]]. |
| | ==== Device Commands ==== |
| | |
| | Sending commands to devices requires that you POST a JSON message to the ''**/v2/api/command**'' URL. |
| | |
| | === set brightness === |
| | |
| | == REST == |
| | <code>''curl -X PUT -u user:password --digest -d brightness=27 http://127.0.0.1:8176/devices/office-lamp''</code> |
| | |
| | == HTTP == |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.device.setBrightness","objectId":123456789,"parameters":{"value":27}}' http://127.0.0.1:8176/v2/api/command</code> |
| | |
| | Insert the ID of the ''office-lamp'' device as the objectId. |
| | |
| | === turn on/turn off === |
| | |
| | == REST == |
| | <code>''curl -X PUT -u user:password --digest -d isOn=1 http://127.0.0.1:8176/devices/office-lamp''</code> |
| | <code>''curl -X PUT -u user:password --digest -d isOn=0 http://127.0.0.1:8176/devices/office-lamp''</code> |
| | |
| | == HTTP == |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.device.turnOn","objectId":123456789}' http://127.0.0.1:8176/v2/api/command</code> |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.device.turnOff","objectId":123456789}' http://127.0.0.1:8176/v2/api/command</code> |
| | |
| | Insert the ID of the ''office-lamp'' device as the objectId. |
| | |
| | === toggle === |
| | |
| | == REST == |
| | <code>''curl -X PUT -u user:password --digest -d toggle=1 http://127.0.0.1:8176/devices/office-lamp''</code> |
| | |
| | == HTTP == |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.device.toggle","objectId":123456789}' http://127.0.0.1:8176/v2/api/command</code> |
| | |
| | Insert the ID of the ''office-lamp'' device as the objectId. |
| | |
| | === change speed index (fan) === |
| | |
| | These examples will set device ''office-ceiling-fan'' to 0 (off), then set to 3 (high), then decrease back to 0 (off). |
| | |
| | == REST == |
| | <code>''curl -X PUT -u user:password --digest -d speedIndex=0 http://127.0.0.1:8176/devices/office-ceiling-fan''</code> |
| | <code>''curl -X PUT -u user:password --digest -d speedIndex=3 http://127.0.0.1:8176/devices/office-ceiling-fan''</code> |
| | <code>''curl -X PUT -u user:password --digest -d speedIndex=dn http://127.0.0.1:8176/devices/office-ceiling-fan''</code> |
| | <code>''curl -X PUT -u user:password --digest -d speedIndex=dn http://127.0.0.1:8176/devices/office-ceiling-fan''</code> |
| | <code>''curl -X PUT -u user:password --digest -d speedIndex=dn http://127.0.0.1:8176/devices/office-ceiling-fan''</code> |
| | |
| | == HTTP == |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.speedcontrol.setSpeedIndex","objectId":123456789,"parameters":{"value":0}}' http://127.0.0.1:8176/v2/api/command</code> |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.speedcontrol.setSpeedIndex","objectId":123456789,"parameters":{"value":3}}' http://127.0.0.1:8176/v2/api/command</code> |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.speedcontrol.decreaseSpeedIndex","objectId":123456789}' http://127.0.0.1:8176/v2/api/command</code> |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.speedcontrol.decreaseSpeedIndex","objectId":123456789}' http://127.0.0.1:8176/v2/api/command</code> |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.speedcontrol.decreaseSpeedIndex","objectId":123456789}' http://127.0.0.1:8176/v2/api/command</code> |
| | |
| | Insert the ID of the ''office-ceiling-fan'' device as the objectId. |
| | |
| | === change sprinkler zones === |
| | |
| | These examples will change device ''irrmaster-pro'' active sprinkler zone to 3 and all off. |
| | |
| | == REST == |
| | <code>''curl -X PUT -u user:password --digest -d activeZone=3 http://127.0.0.1:8176/devices/irrmaster-pro''</code> |
| | <code>''curl -X PUT -u user:password --digest -d activeZone=0 http://127.0.0.1:8176/devices/irrmaster-pro''</code> |
| | |
| | == HTTP == |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.sprinkler.setActiveZone","objectId":123456789,"parameters":{"index":3}}' http://127.0.0.1:8176/v2/api/command</code> |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.sprinkler.setActiveZone","objectId":123456789,"parameters":{"index":0}}' http://127.0.0.1:8176/v2/api/command</code> |
| | |
| | Insert the ID of the ''irrmaster-pro'' device as the objectId. |
| | |
| | === set thermostat setpoints === |
| | |
| | These examples will set device ''thermostat'''s heat and cool setpoints |
| | |
| | == REST == |
| | <code>''curl -X PUT -u user:password --digest -d setpointCool=76 http://127.0.0.1:8176/devices/thermostat''</code> |
| | <code>''curl -X PUT -u user:password --digest -d setpointHeat=70 http://127.0.0.1:8176/devices/thermostat''</code> |
| | |
| | **Increase Heat Setpoint** |
| | |
| | <code>''curl -X PUT -u user:password --digest -d setpointHeat=up http://127.0.0.1:8176/devices/thermostat''</code> |
| | |
| | |
| | == HTTP == |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.thermostat.setCoolSetpoint","objectId":123456789,"parameters":{"value":76}}' http://127.0.0.1:8176/v2/api/command</code> |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.thermostat.setHeatSetpoint","objectId":123456789,"parameters":{"value":70}}' http://127.0.0.1:8176/v2/api/command</code> |
| | |
| | **Increase Heat Setpoint** |
| | |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.thermostat.increaseHeatSetpoint","objectId":123456789}' http://127.0.0.1:8176/v2/api/command</code> |
| | |
| | Insert the ID of the ''thermostat'' device as the objectId. |
| | |
| | === set thermostat mode === |
| | |
| | These examples will set device ''thermostat'''s mode to "cool on" and "auto on" |
| | |
| | == REST == |
| | <code>''curl -X PUT -u user:password --digest -d hvacCurrentMode="cool on" http://127.0.0.1:8176/devices/thermostat''</code> |
| | <code>''curl -X PUT -u user:password --digest -d hvacCurrentMode="auto on" http://127.0.0.1:8176/devices/thermostat''</code> |
| | |
| | |
| | == HTTP == |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.thermostat.setHvacMode","objectId":123456789,"parameters":{"value":"indigo.kHvacMode.Cool"}}' http://127.0.0.1:8176/v2/api/command</code> |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.thermostat.setHvacMode","objectId":123456789,"parameters":{"value":"indigo.kHvacMode.HeatCool"}}' http://127.0.0.1:8176/v2/api/command</code> |
| | |
| | Insert the ID of the ''thermostat'' device as the objectId. |
| | |
| | === set thermostat fan mode === |
| | |
| | These examples will set device ''thermostat'''s fan mode to "always on" and "auto on" |
| | |
| | == REST == |
| | <code>''curl -X PUT -u user:password --digest -d hvacFanMode="always on" http://127.0.0.1:8176/devices/thermostat''</code> |
| | <code>''curl -X PUT -u user:password --digest -d hvacFanMode="auto on" http://127.0.0.1:8176/devices/thermostat''</code> |
| | |
| | |
| | == HTTP == |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.thermostat.setFanMode","objectId":123456789,"parameters":{"value":"indigo.kFanMode.AlwaysOn"}}' http://127.0.0.1:8176/v2/api/command</code> |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.thermostat.setFanMode","objectId":123456789,"parameters":{"value":"indigo.kFanMode.Auto"}}' http://127.0.0.1:8176/v2/api/command</code> |
| | |
| | Insert the ID of the ''thermostat'' device as the objectId. |
| | |
| | ===== Variable Access ===== |
| | |
| | ==== Getting Variables ==== |
| | |
| | === get variable list === |
| | |
| | == REST == |
| | <code>http://username:[email protected]:8176/variables.json</code> |
| | |
| | == HTTP == |
| | <code>http://127.0.0.1:8176/v2/api/indigo.variables?api-key=YOUR-API-KEY</code> |
| | |
| | This will return a JSON list of [[indigo_2022.2_documentation:api#variable_objects|Variable Objects]]. |
| | |
| | === get single variable === |
| | |
| | == REST == |
| | <code>http://username:[email protected]:8176/variables/sprinklerDurationMultiplier.json</code> |
| | |
| | == HTTP == |
| | <code>http://127.0.0.1:8176/v2/api/indigo.variables/123456789?api-key=YOUR-API-KEY</code> |
| | |
| | Insert the ID of the ''sprinklerDurationMultiplier'' variable rather than the name. |
| | |
| | This will return a single [[indigo_2022.2_documentation:api#variable_objects|Variable Object]]. |
| | ==== Variable Commands ==== |
| | |
| | Sending commands to the server requires that you POST a JSON message to the ''**/v2/api/command**'' URL. |
| | |
| | === update variable value === |
| | |
| | == REST == |
| | <code>''curl -X PUT -u user:password --digest -d value=1.23 http://127.0.0.1:8176/variables/sprinklerDurationMultiplier''</code> |
| | |
| | == HTTP == |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.variable.updateValue","objectId":123456789,"parameters":{"value":"1.23"}}' http://127.0.0.1:8176/v2/api/command</code> |
| | |
| | Insert the ID of the ''sprinklerDurationMultiplier'' variable as the objectId. **Note**: variable values are always strings to make sure to enclose the value in quotes. |
| | |
| | ===== Action Group Access ===== |
| | |
| | ==== Getting Action Groups ==== |
| | |
| | === get action group list === |
| | |
| | == REST == |
| | <code>http://username:[email protected]:8176/actions.json</code> |
| | |
| | == HTTP == |
| | <code>http://127.0.0.1:8176/v2/api/indigo.actionGroups?api-key=YOUR-API-KEY</code> |
| | |
| | This will return a JSON list of [[indigo_2022.2_documentation:api#action_group_objects|Action Group Objects]]. |
| | === get single action group === |
| | |
| | == REST == |
| | <code>http://username:[email protected]:8176/actions/party%20scene.json</code> |
| | |
| | == HTTP == |
| | <code>http://127.0.0.1:8176/v2/api/indigo.actionGroups/123456789?api-key=YOUR-API-KEY</code> |
| | |
| | Insert the ID of the ''party scene'' action group rather than the name. |
| | |
| | This will return a single [[indigo_2022.2_documentation:api#action_group_objects|Action Group Object]]. |
| | ==== Action Group Commands ==== |
| | |
| | Sending commands to the server requires that you POST a JSON message to the ''**/v2/api/command**'' URL. |
| | |
| | === execute action group === |
| | |
| | == REST == |
| | <code>''curl -X EXECUTE -u user:password --digest -d value=1.23 http://127.0.0.1:8176/actions/party%20scene''</code> |
| | |
| | == HTTP == |
| | <code>curl -X POST -H "Authorization: Bearer YOUR-API-KEY" -d '{"message":"indigo.actionGroup.execute","objectId":123456789}' http://127.0.0.1:8176/v2/api/command</code> |
| | |
| | Insert the ID of the ''party scene'' action group as the objectId. |
| |