Examples
The following example shows how to switch a light using the REST API.
First, the required authentication steps must be completed (see the "Preparation" and "Authentication" sections). The resulting token can then be used to send the required requests and commands.
First, a GET request is sent to "http://[Smart_Building_Automation_IP]/api/instances". The response contains a list of all instances currently available in the Smart Building Automation system.
{
"statusCode": 200,
"statusText": "success",
"data": [
{
"ID": "SC1_M04.Light1",
"ClassName": "SmartCOM.Light.Light",
"Name": "Roomlight",
"Group": "AreaOutdoor"
},
...
]
}
Since a light is to be switched, "Roomlight" is selected. Its "ClassName", "SmartCOM.Light.Light", can then be used to send a GET request to "http://[Smart_Building_Automation_IP]/api/apps/SmartCOM.Light.Light" and retrieve the available methods and properties.
{
"statusCode": 200,
"statusText": "success",
"data": {
"methods": [
{
"parameter": [],
"name": "SwitchOn",
"type": 0,
"derived": false,
"tags": [
"linkable"
],
"returnType": "void",
"description": "switch light on",
"isStatic": false
},
...
],
"properties": [
{
"name": "IsOn",
"type": "boolean",
"remark": "light switched on",
"declaration": "2",
"derived": true,
"parameter": false,
"tags": [
"linkable"
],
"isStatic": false
},
...
],
"fullName": "SmartCOM.Light.Light",
"displayName": "Light",
"autoStart": false
}
}
Next, a POST request is sent to "http://[Smart_Building_Automation_IP]/api/instances/SC1_M04.Light1/SwitchOn" with the following parameters in the header:
- instanceId: SC1_M04.Light1
- action: SwitchOn
- body: [ ]
This calls the specified method and switches the light on. The current status can be checked by sending a GET request to "http://[Smart_Building_Automation_IP]/api/instances/SC1_M04.Light1/IsOn". The response contains the current status, in this case "true".
{
"statusCode": 200,
"statusText": "success",
"data": true
}