====== 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 == http://username:password@127.0.0.1:8176/devices.json == HTTP == http://127.0.0.1:8176/v2/api/indigo.devices?api-key=YOUR-API-KEY This will return a JSON list of [[indigo_2022.2_documentation:api#device_objects|Device Objects]]. === get single device === == REST == http://username:password@127.0.0.1:8176/devices/office-lamp.json == HTTP == http://127.0.0.1:8176/v2/api/indigo.devices/123456789?api-key=YOUR-API-KEY 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 == ''curl -X PUT -u user:password --digest -d brightness=27 http://127.0.0.1:8176/devices/office-lamp'' == HTTP == 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 Insert the ID of the ''office-lamp'' device as the objectId. === turn on/turn off === == REST == ''curl -X PUT -u user:password --digest -d isOn=1 http://127.0.0.1:8176/devices/office-lamp'' ''curl -X PUT -u user:password --digest -d isOn=0 http://127.0.0.1:8176/devices/office-lamp'' == HTTP == 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 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 Insert the ID of the ''office-lamp'' device as the objectId. === toggle === == REST == ''curl -X PUT -u user:password --digest -d toggle=1 http://127.0.0.1:8176/devices/office-lamp'' == HTTP == 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 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 == ''curl -X PUT -u user:password --digest -d speedIndex=0 http://127.0.0.1:8176/devices/office-ceiling-fan'' ''curl -X PUT -u user:password --digest -d speedIndex=3 http://127.0.0.1:8176/devices/office-ceiling-fan'' ''curl -X PUT -u user:password --digest -d speedIndex=dn http://127.0.0.1:8176/devices/office-ceiling-fan'' ''curl -X PUT -u user:password --digest -d speedIndex=dn http://127.0.0.1:8176/devices/office-ceiling-fan'' ''curl -X PUT -u user:password --digest -d speedIndex=dn http://127.0.0.1:8176/devices/office-ceiling-fan'' == HTTP == 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 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 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 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 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 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 == ''curl -X PUT -u user:password --digest -d activeZone=3 http://127.0.0.1:8176/devices/irrmaster-pro'' ''curl -X PUT -u user:password --digest -d activeZone=0 http://127.0.0.1:8176/devices/irrmaster-pro'' == HTTP == 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 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 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 == ''curl -X PUT -u user:password --digest -d setpointCool=76 http://127.0.0.1:8176/devices/thermostat'' ''curl -X PUT -u user:password --digest -d setpointHeat=70 http://127.0.0.1:8176/devices/thermostat'' **Increase Heat Setpoint** ''curl -X PUT -u user:password --digest -d setpointHeat=up http://127.0.0.1:8176/devices/thermostat'' == HTTP == 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 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 **Increase Heat Setpoint** 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 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 == ''curl -X PUT -u user:password --digest -d hvacCurrentMode="cool on" http://127.0.0.1:8176/devices/thermostat'' ''curl -X PUT -u user:password --digest -d hvacCurrentMode="auto on" http://127.0.0.1:8176/devices/thermostat'' == HTTP == 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 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 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 == ''curl -X PUT -u user:password --digest -d hvacFanMode="always on" http://127.0.0.1:8176/devices/thermostat'' ''curl -X PUT -u user:password --digest -d hvacFanMode="auto on" http://127.0.0.1:8176/devices/thermostat'' == HTTP == 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 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 Insert the ID of the ''thermostat'' device as the objectId. ===== Variable Access ===== ==== Getting Variables ==== === get variable list === == REST == http://username:password@127.0.0.1:8176/variables.json == HTTP == http://127.0.0.1:8176/v2/api/indigo.variables?api-key=YOUR-API-KEY This will return a JSON list of [[indigo_2022.2_documentation:api#variable_objects|Variable Objects]]. === get single variable === == REST == http://username:password@127.0.0.1:8176/variables/sprinklerDurationMultiplier.json == HTTP == http://127.0.0.1:8176/v2/api/indigo.variables/123456789?api-key=YOUR-API-KEY 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 == ''curl -X PUT -u user:password --digest -d value=1.23 http://127.0.0.1:8176/variables/sprinklerDurationMultiplier'' == HTTP == 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 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 == http://username:password@127.0.0.1:8176/actions.json == HTTP == http://127.0.0.1:8176/v2/api/indigo.actionGroups?api-key=YOUR-API-KEY This will return a JSON list of [[indigo_2022.2_documentation:api#action_group_objects|Action Group Objects]]. === get single action group === == REST == http://username:password@127.0.0.1:8176/actions/party%20scene.json == HTTP == http://127.0.0.1:8176/v2/api/indigo.actionGroups/123456789?api-key=YOUR-API-KEY 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 == ''curl -X EXECUTE -u user:password --digest -d value=1.23 http://127.0.0.1:8176/actions/party%20scene'' == HTTP == 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 Insert the ID of the ''party scene'' action group as the objectId.