Get all devices

Function Description:

Get ids for all devices.

Corresponding JS API:
Device.searchObject(sigmaConst.DevAll)
Whether to support multiple devices:

Yes

Resource Information:

Method GET
URL .../devices?q=all&type=number
Requires authentication? Yes


Method Parameters:

Parameter Type Required Description
q String Yes A fixed value: all
type String No A fixed value: number, to get device serial number(for Total Control Version 6.9.0 and later).


Response Parameters:

A JSON string representing an array of objects with the following fields.
If resource URL is ".../devices?q=all", the return value is as follows:

Field Type Description
ids String All device ids

If resource URL is ".../devices?q=all&type=number", the return value is as follows:

Field Type Description
ids int Serial number of all devices.
Note that the device serial number is returned only in MDCC, not in the MDCC, and the returned id value is always 0.


Request Example:
http://localhost:8090/TotalControl/v1/devices?q=all&token=270eq7lXQK8bXYsJ

or

http://localhost:8090/TotalControl/v1/devices?q=all&token=270eq7lXQK8bXYsJ&type=number
Response Example:

If this API executes successfully, it returns:

{
    "ids":[
        "device@795844152",
        "device@795812215"
    ]
}

or

{
    "ids":[
        1,
        2,
        3
    ]
}


Example:

.

Warm tip:
Get the token needed for Total Control script development,see here.

RingoJS Example:
// Import the packages
var {request} = require("ringo/httpclient");
var base64 = require("ringo/base64");

// The username and password are separated by a single : and sent on the wire base64 encoded
var userpass = base64.encode("sigma:3D391497");

// First step: Get the API token
var gettoken = request({
	method: "GET",
	url: "http://localhost:8090/TotalControl/v1/login",
	headers: {
		"Authorization": userpass
	}
});
var ret_token = JSON.parse(gettoken.content); 
var token = ret_token.value.token; 
print("//The value of token is:" + token);

// Second step: Get the device id value of the master device
var getdevice1 = request({
	method: "GET",
	url: "http://localhost:8090/TotalControl/v1/devices?q=all&type=number&token=" + token
});
print("Get the device id,Return value: "+getdevice1.content);
var device = JSON.parse(getdevice1.content).ids; 
print("//The value of device ID is:"+ device);

var getdevice = request({
	method: "GET",
	url: "http://localhost:8090/TotalControl/v1/devices?q=all&token=" + token
});
print("Get the device id,Return value: "+getdevice.content);
var device = JSON.parse(getdevice.content).ids; 
print("//The value of device ID is:"+ device);
The running result of the RingoJS:

In MDCC.
If it executes successfully, it will return:

//The value of token is:p150XKR61SaJ6z9G
Get the device id,Return value: {"ids":[1,2]}
//The value of device ID is:1,2
Get the device id,Return value: {"ids":["device@33254183","device@230441652"]}
//The value of device ID is:device@33254183,device@230441652
Python Example:
#!/user/bin/python
#-*- coding:utf-8 -*-
import base64
import requests

# The username and password are separated by a single : and sent on the wire base64 encoded
user_pass = 'sigma:3D391497'
encodeStr = base64.b64encode(user_pass.encode("UTF-8"))

# First step: Get the API token
LoginUrl = "http://localhost:8090/TotalControl/v1/login"
response = requests.get(LoginUrl, headers={'Authorization':encodeStr})
print("Get the token,Return value: ",response.json())
token = response.json()['value']['token']
print("The value of token is: ",token)

# Second step: Get the device id value of the master device
if token is not None:
    GetDeviceUrl = "http://localhost:8090/TotalControl/v1/devices?q=all&token=" + token
    response = requests.get(url=GetDeviceUrl)
    print("Get the device id,Return value: ", response.json())
    device = response.json()['ids']

    if device is not None:
        print("The value of device id is: ", device)
    else:
        print("Failed to get device id.")
else:
    print("Failed to get token.")
The running result of the python:

If it executes successfully, it will return:

Get the token,Return value:  {'status': True, 'value': {'token': 'SPQxpZO2Qz79oFWG'}}
The value of token is:  SPQxpZO2Qz79oFWG
Get the device id,Return value:  {'ids': ['device@33254183', 'device@230441652']}
The value of device id is:  ['device@33254183', 'device@230441652']