Creating, editing and deleting items

Let’s see how standard operations with items such as creating, editing, and deleting are performed in MiniFinder GO. As an example we’ll take a unit. Manipulations with items of other types are similar to ones described below except editing which differs according to item type.

:!: Attention! To launch this example at MiniFinder GO Kit, change https://hst-api.example.com for https://kit-api.example.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.

Creating unit

Let’s create a unit with name “ips_unit” and device type “IPS”. To do this, we’ll need the request core/create_unit:

https://hst-api.example.com/example/ajax.html?svc=core/create_unit&
	params={
		"creatorId":50935,
		"name":"ips_unit",
		"hwTypeId":96266,
		"dataFlags":1
	}&sid=<your_sid>

Response:

{
    "item": {
        "nm": "ips_unit",
        "cls": 2,
        "id": 652886,
        "uacl": -1
    },
    "flags": 1
}

To check that the unit has indeed been created, perform a search by name:

https://hst-api.example.com/example/ajax.html?svc=core/search_items&
	params={
		"spec":{
			"itemsType":"avl_unit",
			"propName":"sys_name",
			"propValueMask":"ips_unit",
			"sortType":"sys_name"
		},
		"force":1,
		"flags":1,
		"from":0,
		"to":0
	}&sid=<your_sid>

Response:

{
    "searchSpec": {
        "itemsType": "avl_unit",
        "propName": "sys_name",
        "propValueMask": "ips_unit",
        "sortType": "sys_name",
        "propType": ""
    },
    "dataFlags": 1,
    "totalItemsCount": 1,
    "indexFrom": 0,
    "indexTo": 0,
    "items": [{
        "nm": "ips_unit",
        "cls": 2,
        "id": 652886,
        "uacl": -1
    }]
}

The response is not empty, so we can conclude that the unit has been created successfully.

Editing unit

Now we are going to edit the value of the mileage counter of the new unit. To watch the changes, let’s first make the request about the initial value of this counter. To see counter values in the resulting JSON, use the flag 0x00002000 (8192):

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

Response:

{
    "item": {
        "nm": "ips_unit",
        "cls": 2,
        "id": 652886,
        "cfl": 16,
        "cnm": 0,
        "cneh": 0,
        "cnkb": 0,
        "uacl": -1
    },
    "flags": 8193
}

Mileage counter value is placed in the field cnm and it is 0.

To change the value of the counter, use the request unit/update_mileage_counter:

https://hst-api.example.com/example/ajax.html?svc=unit/update_mileage_counter&
	params={
		"itemId":652886,
		"newValue":456
	}&sid=<your_sid>

Response:

{
    "cnm": 456
}

Now let’s check the result of editing using a search request:

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

Response:

{
    "item": {
        "nm": "ips_unit",
        "cls": 2,
        "id": 652886,
        "cfl": 16,
        "cnm": 456,
        "cneh": 0,
        "cnkb": 0,
        "uacl": -1
    },
    "flags": 8193
}

We see that the value in cnm field has changed and it is 456 now, so the editing operation has been successful.

Deleting unit

You can delete an item using the request item/delete_item:

https://hst-api.example.com/example/ajax.html?svc=item/delete_item&
	params={
		"itemId":652886
	}&sid=<your_sid>

Response:

{}

Make a search by ID to make sure that that the operation has been successful:

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

Result:

{
    "error": 7
}