check_unique
To check whether a value is already used, use the core/check_unique method. You can check user names, resource names, phone numbers of units and drivers, and unique IDs of unit devices.
Endpoint
To check one user name, resource name, or phone number, use the following request:
svc=core/check_unique¶ms={
"type": "<text>",
"value": "<text>"
}
To check several values at once or the unique ID of a unit device, use the following request:
svc=core/check_unique¶ms={
"items": [
{
"type": "<text>",
"value": "<text>"
},
{
"hwType": <long>,
"uniqueId": "<text>"
},
...
]
}
Parameters
The request must contain either the type and value parameters or the items parameter. If the request contains both, the type and value parameters are used, and the items parameter is ignored.
| Parameter | Description |
|---|---|
type |
Item type: user, avl_resource, or avl-phones (phone number of a unit or a driver). Unit and driver names don’t have to be unique, so they can’t be checked with this method. To find a unit or a driver by name, use the core/search_items method. |
value |
Value to check: the user name, the resource name, or the phone number. Names are case-sensitive: for example, john_smith and John_Smith are different names. Specify the phone number in the international format with the + character, for example, +37011122233. |
items |
Array of values to check. Each element of the array must contain either the type and value parameters or the hwType and uniqueId parameters. |
hwType |
Device type ID. Used only in the elements of the items array. You can get the ID from the id field in the response of the core/get_hw_types method or from the hw field in the advanced properties of a unit. |
uniqueId |
Unique ID of the unit device (for example, IMEI) specified in the unit properties. Used only in the elements of the items array. You can get it from the uid field in the advanced properties of a unit. The uniqueness is checked for the combination of the unique ID and the device type: the same unique ID can be used with another device type. |
Response
If the value is unique, the following response is returned:
{
"result": 0
}
If the value is already used, the following response is returned:
{
"result": 1
}
If the type parameter has a value not listed in the table above, 0 is returned. The same applies to a device type ID that doesn’t exist.
If you check several values, an array is returned. Each element of the array contains the result for the corresponding element of the items array: 0 or 1. For example:
[0, 1, 0]
If the request fails, an error code is returned.
Error codes
| Error code | Description |
|---|---|
| 4 | Wrong input parameters: the request doesn’t match any of the formats above, or an element of the items array has a wrong format. |
| 1003 | Failed to check the request limits, or the limit on the number of API requests according to a certain rule is exceeded. See Limitations. |
Examples
Below are examples of the core/check_unique request.
Checking a user name
To check whether the john_smith user name is already used, specify user in the type parameter and the user name in the value parameter. Both parameters are required.
svc=core/check_unique¶ms={"type":"user","value":"john_smith"}
Response: {"result":1}. The user name is already used.
Checking the unique ID of a unit device
The request checks whether the 123456789012345 unique ID with the 96266 device type ID is already used. A unique ID can be checked only in the items array, so the array contains one element with the required hwType and uniqueId parameters.
svc=core/check_unique¶ms={"items":[{"hwType":96266,"uniqueId":"123456789012345"}]}
Don’t add the type and value parameters to this element, even with empty values. Otherwise, 0 is returned.
Response: [0]. The unique ID isn’t used.
Checking several values
The request checks the john_smith user name, the Delivery Service resource name, and the 123456789012345 unique ID with the 96266 device type ID.
svc=core/check_unique¶ms={"items":[{"type":"user","value":"john_smith"},{"type":"avl_resource","value":"Delivery Service"},{"hwType":96266,"uniqueId":"123456789012345"}]}
Response: [1,0,0]. The results are in the same order as the elements of the items array: the user name is already used, the resource name and the unique ID aren’t used.