Table of Contents

Item search

One of the most common requests in Wialon are search requests. Two kinds of search are possible in Wialon:

Search item by ID

The search by item ID is the simplest one. If item ID is known, any available information about this item can be fetched by using the request core/search_item. For example, lets find unit by ID. To provide the response with position of a unit the flag 0x00000400 must be set. Besides, we will set the flag 0x00000001 to get unit name. Detailed information about flags and data formats is given in the chapter Data format.

<your_wialon_pro_address>/ajax.html?svc=core/search_item&
	params={
		"itemId":48,
		"flags":1025
	}&ssid=<your_sid>

Response:

{
    "nm": "Auto001",
    "cls": 3,
    "id": 48,
    "pos": {
        "t": 1362551743,
        "f": 7,
        "tp": "udp",
        "l": "",
        "y": 55.76416,
        "x": 37.65644,
        "z": 0,
        "s": 43,
        "c": 345,
        "sc": 255,
        "y2": 0,
        "x2": 0,
        "i": 1,
        "o": 0,
        "p": {
            "adc1": 0.64453125
        }
    },
    "lmsg": "dup"
}

From the response, we learn that unit with specified ID is called “Auto001” and its last known position is 37.65644 NL and 55.76416 EL.

Search items by property

Method from the example above is convenient for those cases, when we need to learn more about item with known ID. But often it is needed to find several items, that will satisfy search conditions. For this purposes the request core/search_items is used. For example, all users can be found by making the following request:

<your_wialon_pro_address>/ajax.html?svc=core/search_items&
	params={
		"spec":{
 			"itemsType":"user",
			"propName":"sys_name",
    			"propValueMask":"*",
			"sortType":"sys_name"
		},
                "force":1,
          	"flags":1,
          	"from":0,
          	"to":0xffffffff
	}&ssid=<your_sid>

Asterisk in the parameter propValueMask means that in the result array there will be users with any values in the field sys_name (that is users of any names). It means all available users will be present in the result. Value “1” of the parameter flags means that basic information about the item must be included in the result. Detailed information about user flags is given in the chapter Users. Values of the parameters from and to which equals to 0 and 0xffffffff accordingly, indicate that all found users should be returned.

Response:

{
    "searchSpec": {
        "itemsType": "user",
        "propName": "sys_name",
        "propValueMask": "*",
        "sortType": "sys_name"
    },
    "dataFlags": 1,
    "totalItemsCount": 4,
    "indexFrom": 0,
    "indexTo": 3,
    "items": [{
        "nm": "newuser",
        "cls": 1,
        "id": 49
    }, {
        "nm": "qwerty",
        "cls": 1,
        "id": 30
    }, {
        "nm": "user1",
        "cls": 1,
        "id": 39
    }, {
        "nm": "wialon",
        "cls": 1,
        "id": 7
    }]
}

Search units by creator

<your_wialon_pro_address>/ajax.html?svc=core/search_items&
	params={
		"spec":{
 			"itemsType":"avl_unit",
			"propName":"22sys_user_creator",
    			"propValueMask":"22ac745a8ec8eb54469607d30bfeffb807",      /* creators "gd" property */
			"sortType":"sys_name"
		},
                "force":1,
          	"flags":1,
          	"from":0,
          	"to":0xffffffff
	}&ssid=<your_sid>

Response:

{
    searchSpec: {
        itemsType: "avl_unit",
        propName: "sys_user_creator",
        propValueMask: "ac745a8ec8eb54469607d30bfeffb807",
        sortType: "sys_name"
    },
    dataFlags: 1,
    totalItemsCount: 3,
    indexFrom: 0,
    indexTo: 2,
    items: [{
        nm: "unit1",
        cls: 3,
        id: 554
    },{
        nm: "unit2",
        cls: 3,
        id: 558
    },{
        nm: "unit3",
        cls: 3,
        id: 559
    }]
}