Item search

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

:!: Attention! To launch this example at Wialon Kit, change https://hst-api.wialon.com for https://kit-api.wialon.com in all requests and use user name and password of your account to login to the system or name and password of demo user kitdemo kitdemo.

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, you need to know the last location of a unit which ID is 34868. To get information about unit location, the flag 0x00000400 (1024) must be set. Besides, we will set the flag 0x00000001 (1) to get unit name. Detailed information about flags and data formats is given in the chapter Data format.

https://hst-api.wialon.com/wialon/ajax.html?svc=core/search_item&
	params={
		"id":34868,
		"flags":1025
	}&sid=<your_sid>

Response:

{
    "item": {
        "nm": "Bavarian Tractor",
        "cls": 2,
        "id": 34868,
        "pos": {
            "t": 1358761631,
            "y": 53.9205504,
            "x": 27.4921152,
            "z": 238,
            "s": 0,
            "c": 102,
            "sc": 10
        },
        "lmsg": {
            "t": 1358761631,
            "f": 3,
            "tp": "ud",
            "pos": {
                "y": 53.9205504,
                "x": 27.4921152,
                "z": 238,
                "s": 0,
                "c": 102,
                "sc": 10
            },
            "i": 0,
            "p": {
                "param22": 3,
                "adc1": 12.352,
                "pwr_ext": 12.356,
                "param199": 0,
                "param241": 25701,
                "battery_charge": 0
            }
        },
        "uacl": 638138188323
    },
    "flags": 1025
}

From the response, we learn that unit with specified ID is called Bavarian Tractor and its last known position is 53.9205504 NL and 27.4921152 EL.

Search items by property

For more complicated searches, the request core/search_items is used. For example, all users can be found by making the following request:

https://hst-api.wialon.com/wialon/ajax.html?svc=core/search_items&
	params={
		"spec":{
 			"itemsType":"user",
			"propName":"sys_name",
    			"propValueMask":"*",
			"sortType":"sys_name"
		},
                "force":1,
          	"flags":1,
          	"from":0,
          	"to":0
	}&sid=<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. Zero values of the parameters from and to indicate that all found users should be returned.

Response:

{
    "searchSpec": {
        "itemsType": "user",
        "propName": "sys_name",
        "propValueMask": "*",
        "sortType": "sys_name"
    },
    "dataFlags": 1,
    "totalItemsCount": 1,
    "indexFrom": 0,
    "indexTo": 0,
    "items": [{
        "nm": "test_6512789",
        "cls": 1,
        "id": 648548,
        "uacl": -1
    }]
}

The example above fits only to search items like resources, retranslators, units, unit groups, users and routes. But some of those items such as resources or routes normally contain subitems, for example, geofences are subitems of resource. In case of search in subitems, you need to add one more parameter in search specification – propType – and set its value to “propitemname”, and in the parameter propName indicate subitem name. List of all subitems can be found in the chapter core/search_items.

As an example, let's examine situation in which we need to find resources which contain geofences with names containing the phrase “bing”. Let's say the returned result must contain only two first found resources. To have not only resources in the result but also geofences, the flag 0x00001000 (4096) must be set in addition to the basic flag.

https://hst-api.wialon.com/wialon/ajax.html?svc=core/search_items&
	params={
		"spec":{
			"itemsType":"avl_resource",
			"propName":"zones_library",
			"propValueMask":"*bing*",
			"sortType":"zones_library",
			"propType":"propitemname"
		},
		"force":1,
		"flags":4097,
		"from":0,
		"to":1
	}&sid=<your_sid>

Response:

{
    "searchSpec": {
        "itemsType": "avl_resource",
        "propName": "zones_library",
        "propValueMask": "*bing*",
        "sortType": "zones_library",
        "propType": "propitemname"
    },
    "dataFlags": 4097,
    "totalItemsCount": 1,
    "indexFrom": 0,
    "indexTo": 0,
    "items": [{
        "nm": "template_ru",
        "cls": 3,
        "id": 163266,
        "zl": {
            "1": {
                "n": "Ветютнев",
                "d": "",
                "id": 1,
                "f": 1,
                "t": 2,
                "e": 60774,
                "b": {
                    "min_x": 43.5271002776,
                    "min_y": 49.7636455785,
                    "max_x": 43.5622908598,
                    "max_y": 49.7794993012,
                    "cen_x": 43.5446955687,
                    "cen_y": 49.7715724398
                }
            },
            "2": {
                "n": "Волгоград_конечный_пункт",
                "d": "",
                "id": 2,
                "f": 1,
                "t": 2,
                "e": 62438,
                "b": {
                    "min_x": 44.3872954375,
                    "min_y": 48.6329175554,
                    "max_x": 44.6300246245,
                    "max_y": 48.856592389,
                    "cen_x": 44.508660031,
                    "cen_y": 48.7447549722
                }
            },
            "3": {
                "n": "Михайловка_база",
                "d": "",
                "id": 3,
                "f": 1,
                "t": 2,
                "e": 4566,
                "b": {
                    "min_x": 43.107388,
                    "min_y": 50.009182,
                    "max_x": 43.294156,
                    "max_y": 50.119376,
                    "cen_x": 43.200772,
                    "cen_y": 50.064279
                }
            },
            "4": {
                "n": "Шмитовский",
                "d": "",
                "id": 4,
                "f": 1,
                "t": 1,
                "e": 39844,
                "b": {
                    "min_x": 37.5347102757,
                    "min_y": 55.7544919087,
                    "max_x": 37.5596537243,
                    "max_y": 55.7598140913,
                    "cen_x": 37.546216,
                    "cen_y": 55.757443
                }
            },
            "5": {
                "n": "bingo",
                "d": "",
                "id": 5,
                "f": 1,
                "t": 3,
                "e": 44015,
                "b": {
                    "min_x": 37.5537148786,
                    "min_y": 55.7585093867,
                    "max_x": 37.5576971214,
                    "max_y": 55.7607546133,
                    "cen_x": 37.555706,
                    "cen_y": 55.759632
                }
            }
        },
        "uacl": 2200454562339
    }]
}

As a result, one resource with 5 geofences was found. One of them contains bing in its name.

Follow us on Facebook Gurtam Wialon Twitter Gurtam Wialon info@gurtam.com   |   Copyright © 2002-2024 Gurtam