Executing several commands at once

:!: 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.

Several commands can be executed with one request. In this case, the response is also presented in one JSON. For example we may need to send an online message to many users.

Let's query all users available to “wialon_test” on Wialon Hosting server:

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>

Response:

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

As we can see from the response, two users are available and their IDs are 648548 and 656124. Let's send them online messages using one request core/batch. To send an online messages, use the command user/update_user_notification. We will use different styles for text - parameter “d”. Its detailed description is given in the chapter Send on-line notices.

https://hst-api.wialon.com/wialon/ajax.html?svc=core/batch&
	params=[{
		"svc":"user/update_user_notification",
		"params":{
			"h":"Hi there!",
			"d":"{\"body\":\"<span style=\\\"font-size:16px;color:green\\\">New notification with custom text format</span>
\",\"head\":{\"c\":52428,\"fs\":\"18\"}",
			"s":"",
			"ttl":1359015606,
			"itemId":648548,
			"id":0,
			"callMode":"create"
		}
	},{
		"svc":"user/update_user_notification",
		"params":{
			"h":"Hi there!",
			"d":"{\"body\":\"<p style=\\\"text-align: center;\\\"><b style=\\\"text-align: center;\\\"><i style=\\\"text-align: center; color: rgb(0, 0, 0);\\\"><span style=\\\"color:rgb(0,0,255);text-align: center;\\\">Text bold cursive blue color in the centre</span></i></b></p>\",\"head\":{\"c\":39219,\"fs\":\"12\"},\"multiple\":1}",
			"s":"",
			"ttl":1359015606,
			"itemId":656124,
			"id":0,
			"callMode":"create"
		}
	}]&sid=<your_sid>

Response:

[
    [1, {
        "id": 1,
        "t": 1359013247,
        "d": {\"body\":\"<span style=\\\"font-size:16px;color:green\\\">New notification with custom text format</span>
\",\"head\":{\"c\":52428,\"fs\":\"18\"}",
        "h": "Hi there!",
        "s": ""
    }],
    [1, {
        "id": 1,
        "t": 1359013247,
        "d": "{\"body\":\"<p style=\\\"text-align: center;\\\"><b style=\\\"text-align: center;\\\"><i style=\\\"text-align: center; color: rgb(0, 0, 0);\\\"><span style=\\\"color:rgb(0,0,255);text-align: center;\\\">Text bold cursive blue color in the centre</span></i></b></p>\",\"head\":{\"c\":39219,\"fs\":\"12\"},\"multiple\":1},
        "h": "Hi there!",
        "s": ""
    }]
]

To check whether the notices have been sent indeed, log in to the system as those users and see.

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