Differences

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

Link to this comparison view

en:pro:remoteapi:codesamples:update_item [17/04/2013 13:41]
zuve
en:pro:remoteapi:codesamples:update_item [29/11/2013 13:31]
Line 1: Line 1:
-{{indexmenu_n>​4}} 
-====== Creating, editing and deleting items ====== 
  
-Let's see how standard operations with items such as creating, editing, and deleting are performed in Wialon. 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. 
- 
-===== Creating unit ===== 
-Let's create a unit with name "​ips_unit"​ and device type "​Wialon IPS" (list of available device types you can get using request [[../​apiref/​core/​get_hw_types|get_hw_types]]). To do this, we'll need the request [[../​apiref/​core/​create_unit|core/​create_unit]]:​ 
-<​code>​ 
-<​your_wialon_pro_address>/​ajax.html?​svc=core/​create_unit&​ 
- params={ 
- "​creatorId":​7,​ 
- "​name":"​ips_unit",​ 
- "​hwType":​6 
- }&​ssid=<​your_sid>​ 
-</​code>​ 
- 
-Response: 
-<code javascript>​ 
-{ 
-    "​nm":​ "​ips_unit",​ 
-    "​cls":​ 3, 
-    "​id":​ 51, 
-    "​gd":​ "​8a028a562774e6adb211254e358c9c5e",​ 
-    "​prp":​ {}, 
-    "​pup":​ {}, 
-    "​crt":​ 7, 
-    "​bact":​ 27, 
-    "​uid":​ "",​ 
-    "​hw":​ 6, 
-    "​ph":​ "",​ 
-    "​psw":​ "",​ 
-    "​cmds":​ {}, 
-    "​pos":​ {}, 
-    "​lmsg":​ {}, 
-    "​drv":​ "",​ 
-    "​sens":​ {}, 
-    "​sens_max":​ -1, 
-    "​cfl":​ 0, 
-    "​cnm":​ 0, 
-    "​cneh":​ 0, 
-    "​cml":​ {}, 
-    "​cml_max":​ -1, 
-    "​si":​ {}, 
-    "​simax":​ -1, 
-    "​rc":​ {}, 
-    "​rcmax":​ -1, 
-    "​ugi":​ 0, 
-    "​ugs":​ [], 
-    "​flds":​ {}, 
-    "​flds_max":​ -1 
-} 
-</​code>​ 
- 
-To check that the unit has indeed been created, perform a [[../​apiref/​core/​search_items|search]] by name: 
-<​code>​ 
-<​your_wialon_pro_address>/​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":​0xffffffff 
- }&​ssid=<​your_sid>​ 
-</​code>​ 
- 
-Response: 
-<code javascript>​ 
-{ 
-    "​searchSpec":​ { 
-        "​itemsType":​ "​avl_unit",​ 
-        "​propName":​ "​sys_name",​ 
-        "​propValueMask":​ "​ips_unit",​ 
-        "​sortType":​ "​sys_name"​ 
-    }, 
-    "​dataFlags":​ 1, 
-    "​totalItemsCount":​ 1, 
-    "​indexFrom":​ 0, 
-    "​indexTo":​ 0, 
-    "​items":​ [{ 
-        "​nm":​ "​ips_unit",​ 
-        "​cls":​ 3, 
-        "​id":​ 51 
-    }] 
-} 
-</​code>​ 
-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 0x00000800: 
- 
-<​code>​ 
-<​your_wialon_pro_address>/​ajax.html?​svc=core/​search_item&​ 
- params={ 
- "​itemId":​51,​ 
- "​flags":​2049 
- }&​ssid=<​your_sid>​ 
-</​code>​ 
-Response: 
-<code javascript>​ 
-{ 
-    "​nm":​ "​ips_unit",​ 
-    "​cls":​ 3, 
-    "​id":​ 51, 
-    "​drv":​ "",​ 
-    "​sens":​ {}, 
-    "​sens_max":​ -1, 
-    "​cfl":​ 16, 
-    "​cnm":​ 0, 
-    "​cneh":​ 0, 
-    "​si":​ {}, 
-    "​simax":​ -1 
-} 
-</​code>​ 
-Mileage counter value is placed in the field //cnm// and it is 0. 
- 
-To change the value of the counter, use the request [[../​apiref/​unit/​update_mileage_counter|unit/​update_mileage_counter]]:​ 
-<​code>​ 
-<​your_wialon_pro_address>/​ajax.html?​svc=unit/​update_mileage_counter&​ 
- params={ 
- "​itemId":​652886,​ 
- "​newValue":​2049 
- }&​ssid=<​your_sid>​ 
-</​code>​ 
-Response: 
-<code javascript>​ 
-{ 
-    "​cnm":​ 456 
-} 
-</​code>​ 
- 
-Now let's check the result of editing using a search request: ​ 
-<​code>​ 
-<​your_wialon_pro_address>/​ajax.html?​svc=core/​search_item&​ 
- params={ 
- "​itemId":​51,​ 
- "​flags":​2049 
- }&​ssid=<​your_sid>​ 
-</​code>​ 
-Response: 
-<code javascript>​ 
-{ 
-    "​nm":​ "​ips_unit",​ 
-    "​cls":​ 3, 
-    "​id":​ 51, 
-    "​drv":​ "",​ 
-    "​sens":​ {}, 
-    "​sens_max":​ -1, 
-    "​cfl":​ 16, 
-    "​cnm":​ 456, 
-    "​cneh":​ 0, 
-    "​si":​ {}, 
-    "​simax":​ -1 
-} 
-</​code>​ 
-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 [[../​apiref/​item/​delete_item|core/​delete_item]]:​ 
-<​code>​ 
-<​your_wialon_pro_address>/​ajax.html?​svc=item/​delete_item&​ 
- params={ 
- "​itemId":​51 
- }&​ssid=<​your_sid>​ 
-</​code>​ 
-Response: 
-<code javascript>​ 
-{ 
-    "​error":​ 0 
-} 
-</​code>​ 
- 
-Make a search by ID to make sure that that the operation has been successful: 
-<​code>​ 
-<​your_wialon_pro_address>/​ajax.html?​svc=core/​search_item&​ 
- params={ 
- "​itemId":​51,​ 
- "​flags":​1 
- }&​ssid=<​your_sid>​ 
-</​code>​ 
-Response: 
-<code javascript>​ 
-{ 
-    "​error":​ 7 
-} 
-</​code>​ 
Follow us on Facebook Gurtam Wialon Twitter Gurtam Wialon info@gurtam.com   |   Copyright © 2002-2024 Gurtam