Differences

This shows you the differences between two versions of the page.

Link to this comparison view

en:local:remoteapi1504:codesamples:batch [20/05/2014 11:49] (current)
Line 1: Line 1:
 +{{indexmenu_n>​11}}
 +====== Executing several commands at once ======
  
 +//:!: Attention!//​ To launch this example at Wialon Kit, change **<​nowiki>​https://​hst-api.wialon.com</​nowiki>​** for **<​nowiki>​https://​kit-api.wialon.com</​nowiki>​** 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 [[http://​wialonb3.gurtam.com/​|Wialon Hosting]] server:
 +<​code>​
 +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>​
 +</​code>​
 +
 +Response:
 +<code javascript>​
 +{
 +    "​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
 +    }]
 +}
 +</​code>​
 +
 +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 [[../​apiref/​core/​batch|core/​batch]]. To send an online messages, use the command **user/​update_user_notification**. Its detailed description is given in the chapter [[../​apiref/​user/​update_user_notification]].
 +
 +<​code>​
 +https://​hst-api.wialon.com/​wialon/​ajax.html?​svc=core/​batch&​
 + params=[{
 + "​svc":"​user/​update_user_notification",​
 + "​params":​{
 + "​h":"​Hi there!",​
 + "​d":";​-)",​
 + "​s":"",​
 + "​ttl":​1359015606,​
 + "​itemId":​648548,​
 + "​id":​0,​
 + "​callMode":"​create"​
 + }
 + },{
 + "​svc":"​user/​update_user_notification",​
 + "​params":​{
 + "​h":"​Hi there!",​
 + "​d":";​-)",​
 + "​s":"",​
 + "​ttl":​1359015606,​
 + "​itemId":​656124,​
 + "​id":​0,​
 + "​callMode":"​create"​
 + }
 + }]&​sid=<​your_sid>​
 +</​code>​
 +
 +Response:
 +<code javascript>​
 +[
 +    [1, {
 +        "​id":​ 1,
 +        "​t":​ 1359013247,
 +        "​d":​ ";​-)",​
 +        "​h":​ "Hi there!",​
 +        "​s":​ ""​
 +    }],
 +    [1, {
 +        "​id":​ 1,
 +        "​t":​ 1359013247,
 +        "​d":​ ";​-)",​
 +        "​h":​ "Hi there!",​
 +        "​s":​ ""​
 +    }]
 +]
 +</​code>​
 +
 +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-2020 Gurtam