search_items
To search for items by their properties, use the core/search_items method. To get a single item by its ID, use core/search_item.
svc=core/search_items¶ms={
"spec":{
"itemsType":"<text>",
"propName":"<text>",
"propValueMask":"<text>",
"sortType":"<text>",
"propType":"<text>",
"or_logic":<uint>
},
"force":<uint>,
"flags":<long>,
"from":<uint>,
"to":<uint>
}
Parameters
| Name | Description |
|---|---|
| spec | Search specification. |
| itemsType | Item type (see the list below). |
| propName | The name of the property by the value of which you want to search (see the list of possible properties below). You can use the character |. |
| propValueMask | The property value mask. You can use the following characters: * | , > < =. |
| sortType | The name of the property used for sorting. |
| propType | Property type (see the list below). |
| or_logic | The flag of the OR logic for the propName parameter: 1 to use the OR logic, 0 to use the AND logic (see Search by multiple properties section). If the parameter isn’t specified or isn’t an integer, 0 is used. |
| force | Depending on the value:
|
| flags | Flags with properties for the returned result. The value of this parameter depends on the item type. Use the flag table of the type you request: Units, Unit groups, Resources, Retranslators, Routes, Users. |
| from | The index of the first returned item. To start a new search, specify 0. If the value is greater than the index of the last found item, or greater than to when to isn’t 0, error 4 is returned. If no items are found, the items array is empty ([]) and no error is returned. |
| to | The index of the last returned item. If 0 is specified, or the value is greater than the index of the last found item, all items beginning from the index specified in the from parameter are returned. |
The request doesn’t check whether the itemsType, propName, propType, and sortType values exist. An unknown value doesn’t cause an error. For example, if itemsType contains an unknown item type, or no found item has the property specified in propName, the items array is empty. An unknown propType value is processed as property.
Flag values are specific to the item type. Values up to
0x80are mostly the same for all types, but starting from0x100the same number selects different data. For example,0x100 (256)returns advanced properties foravl_unitand drivers foravl_resource. A flag that doesn’t apply to the requested type is ignored without an error, and the response simply omits that data.
Item types
Item types (itemsType parameter):
avl_resource: resource;avl_retranslator: retranslator;avl_unit: unit;avl_unit_group: unit group;user: user;avl_route: route.
To get the list of hardware types, use core/get_hw_types.
Item properties
Item properties (propName and sortType parameters):
sys_name: item name;sys_id: item ID;sys_unique_id: unique unit ID (IMEI);sys_phone_number: unit phone number;sys_phone_number2: unit second phone number;sys_user_creator: creator ID;rel_user_creator_name: creator name;sys_billing_account_guid: account ID;rel_billing_account_name: account name;rel_billing_parent_account_name: parent account name;rel_billing_plan_name: billing plan name;sys_comm_state: hardware state (1: enabled, 0: disabled);rel_hw_type_name: hardware name;rel_hw_type_id: hardware ID;sys_account_balance: account balance;sys_account_days: account days;sys_account_enable_parent: dealer rights (1: on, 0: off);sys_account_disabled: account blocked (1: yes, 0: no);rel_account_disabled_mod_time: last modification time for thesys_account_disabledproperties, UNIX time;rel_account_units_usage: number of units in the account;rel_account_activated_units: number of activated units in the account (only for accounts);rel_business_sphere: name of the business sphere of the account (see account/get_business_spheres);rel_deactivation_time: unit deactivation time, UNIX time (0 if the unit is active);rel_imported_time: unit import time, UNIX time (0 if the unit wasn’t imported);rel_act_code: ID (guid) of the unit activation code (see unit/get_billing_code);rel_act_code_tme: expiration time of the unit activation code, UNIX time (0 if the unit has no code);rel_last_msg_date: last message time, UNIX time;rel_is_account: whether the resource is an account (1: yes, 0: no);login_date: last login time, UNIX time;retranslator_enabled: retranslator state (1: started, 0: stopped);rel_retranslator_protocol: retranslator protocol name;rel_retranslator_server: retranslator server address;rel_retranslator_history_progress: progress of history retranslation;rel_retranslator_units_name: name of a unit added to the retranslator;rel_creation_time: creation time;rel_group_unit_count: the number of units in a group;rel_customfield_name: the name of the custom field of the item;rel_customfield_value: the value of the custom field of the item;rel_profilefield_name: the name of the profile field of the unit;rel_profilefield_value: the value of the profile field of the unit;rel_adminfield_name: the name of the admin field of the item;rel_adminfield_value: the value of the admin field of the item;rel_customfield_name_value: the name and value of the custom field of the item, separated by:;rel_profilefield_name_value: the name and value of the profile field of the unit, separated by:;rel_adminfield_name_value: the name and value of the admin field of the item, separated by:.
Custom and admin fields are available for units, unit groups, users, and resources. Profile fields are available only for units.
In Wialon Local, the rel_business_sphere property is available starting from version 2304, rel_account_activated_units starting from version 2404, and rel_imported_time starting from version 2504. The rel_act_code and rel_act_code_tme properties aren’t available in Wialon Local.
For more values of this parameter, see the table below.
Property types
Property types (propType parameter):
property: property;list: list;propitemname: subitem name (for example, geofence is a subitem of resource);creatortree: chain of creators (returns the items whose chain of creators contains the user specified in thepropValueMaskparameter);accounttree: chain of accounts (returns the items whose chain of accounts contains the account specified in thepropValueMaskparameter);customfield: custom fields;profilefield: unit profile;adminfield: administrative fields;servicename: services.
If propType isn’t specified or has an unknown value, property is used.
In Wialon Local, the servicename type is available starting from version 2404.
Subitems
If you want to search subitems, set the propitemname value for the propType parameter. Then, other parameters can have any of the following values:
Item (itemsType parameter) |
Subitem (propName and sortType parameters) |
Description |
|---|---|---|
avl_unit |
unit_sensors |
Sensors. |
avl_unit |
unit_commands |
Commands. |
avl_unit |
service_intervals |
Service intervals. |
avl_resource |
drivers |
Drivers. |
avl_resource |
driver_groups |
Driver groups. |
avl_resource |
jobs |
Jobs. |
avl_resource |
notifications |
Notifications. |
avl_resource |
trailers |
Trailers. |
avl_resource |
trailer_groups |
Trailer groups. |
avl_resource |
zones_library |
Geofences. |
avl_resource |
reporttemplates |
Report templates. |
avl_resource |
orders |
Orders. |
avl_route |
rounds |
Rides. |
avl_route |
route_schedules |
Schedules. |
avl_retranslator |
retranslator_units |
Retranslator units. |
avl_unitavl_unit_groupuseravl_resource |
custom_fields |
Custom fields. |
avl_unitavl_unit_groupuseravl_resource |
admin_fields |
Admin fields. |
Sorting types
By default, direct sorting works as follows:
- any name is split into bits for sorting (symbols, digits);
- digits are sorted first, and then symbols;
-symbol is considered a hyphen and is sorted before digits (see the special sorting);- system supports decimal mark numbers (3.12) and floating point numbers (2e10; 5.1E-2).
The following sorting types are available:
| Type | Description |
|---|---|
| Direct | Returns values sorted in ascending order:"sortType":"<item_property>" |
| Reverse | Returns values by sorted in descending order:"sortType":"!<item_property>" |
| Combined | Returns values sorted by the first property, then in case of values equality by the second property, and so on:"sortType":"<property1>,!<property2>" |
| Special | According to this sorting, the - symbol is considered a negative number sign. By default, the - symbol is considered a hyphen, not a minus."sortType":"-<item_property>" |
Search by multiple properties
You can search for elements by several properties at once. For example:
"itemsType":"avl_resource","propName":"rel_is_account,*","propValueMask":"1,qwe","sortType":"sys_name","propType":"property,customfield"
The number of properties in the propName, propType and propValueMask parameters should be the same because they are calculated by three, respectively. The system doesn’t check this: if the numbers differ, no error is returned, but the search result may be different from what you expect.
The AND logic is used by default for the propName parameter. In the example above, the system finds all accounts (rel_is_account is 1) that have a custom field with the name or value qwe.
To enable the OR logic for the propName parameter, specify "or_logic":1 in the request.
Using comparison operators in search
In the propValueMask parameter, you can use the following comparison operators: <, >, =, >=, <=. If the search criterion is a string field, the system searches for numbers only at the beginning of its value. If the search criterion is a number field, the whole value is analyzed.
Example 1
"itemsType":"avl_unit","propName":"sys_name,sys_name","propValueMask":">=32,<33.5"
The search results list all units the names of which start with numbers between 32 and 33.5.
Example 2
"itemsType":"avl_resource","propName":"sys_account_balance,sys_account_balance","propValueMask":">2,<=23"
The search results list all resources and accounts the balance of which is greater than 2 and less than or equal to 23.
You can also use the = operator if the field value starts with > or <.
Example 3
"itemsType":"avl_unit","propName":"sys_name","propValueMask":"=>123<,=<123>"
The search results list all available units with the names >123< and <123>.
Search active or deactivated units
There’s no separate search property for the unit activation state. To find active or deactivated units, use the rel_deactivation_time property. For active units, its value is 0. For deactivated units, it’s the deactivation time.
Search for active units:
"itemsType":"avl_unit","propName":"rel_deactivation_time","propValueMask":"0","sortType":"sys_name"
Search for deactivated units:
"itemsType":"avl_unit","propName":"rel_deactivation_time","propValueMask":">0","sortType":"sys_name"
To get the activation state of each found unit, specify the 0x100 flag in the request and check the act key in the advanced properties of the unit.
Returned result
{
"searchSpec": { /* search specification */
"itemsType": "<text>", /* items type */
"propName": "<text>", /* property name */
"propValueMask": "<text>", /* property value mask */
"sortType": "<text>", /* property name for sorting */
"propType": "<text>", /* property type */
"or_logic": "<text>" /* OR logic flag: "0" or "1" */
},
"dataFlags": <uint>, /* applied data flags */
"totalItemsCount": <uint>, /* quantity of found items */
"indexFrom": <uint>, /* beginning index */
"indexTo": <uint>, /* ending index */
"items": [{...}] /* found items */
}
The indexTo value is the to value from the request, limited to the index of the last found item. If to is 0 in the request or no items are found, indexTo is 0.
The format of items array depends on the item type. All formats are described in the Data format section.
Possible error codes:
| Code | Description |
|---|---|
| 4 | Wrong input parameters. For example, a required parameter is missing, or the from value is greater than the index of the last found item or greater than to when to isn’t 0. |