|
|
en:local:remoteapi1504:codesamples:resources [20/05/2014 11:49] |
en:local:remoteapi1504:codesamples:resources [20/05/2014 11:49] (current) |
| {{indexmenu_n>5}} |
| ====== Resource ====== |
| |
| In the previous sample, we've created, edited, and deleted a unit. Units (like users, retranslators, unit groups etc.) are independent items. However, there are sub-items in Wialon which exist as a part of an independent item. For instance, a resource can have such sub-items like geofences, notifications, jobs, POIs, drivers etc. |
| |
| Standard operations with sub-items a bit differ from those with independent items. In this example, we'll examine creating, editing and deleting a POI as a sub-item of a resource. |
| |
| |
| //:!: 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**//. |
| |
| ===== Creating POI ===== |
| Let's create a POI using the request [[../apiref/resource/update_poi|resource/update_poi]]: |
| <code> |
| https://hst-api.wialon.com/wialon/ajax.html?svc=resource/update_poi& |
| params={ |
| "itemId":50936, |
| "id":0, |
| "callMode":"create", |
| "n":"gurtam", |
| "d":"poi", |
| "y":53.91069937030936, |
| "x":27.516643322771575, |
| "r":100, |
| "f":1, |
| "c":16733440, |
| "tc":0, |
| "ts":20, |
| "min":0, |
| "max":18 |
| }&sid=<your_sid> |
| </code> |
| Response: |
| <code javascript> |
| [2, { |
| "id": 1, |
| "n": "gurtam", |
| "y": 53.9106993703, |
| "x": 27.5166433228, |
| "t": 0, |
| "i": 6515, |
| "e": 48223 |
| }] |
| </code> |
| |
| To check that the POI has been created and to get detailed information about it, make the request [[../apiref/resource/get_poi_data|get_poi_data]]: |
| <code> |
| https://hst-api.wialon.com/wialon/ajax.html?svc=resource/get_poi_data& |
| params={ |
| "itemId":50936, |
| "col":[1] |
| }&sid=<your_sid> |
| </code> |
| Response: |
| <code javascript> |
| [{ |
| "id": 1, |
| "n": "gurtam", |
| "d": "poi", |
| "y": 53.9106993703, |
| "x": 27.5166433228, |
| "r": 100, |
| "f": 1, |
| "c": 16733440, |
| "tc": 0, |
| "ts": 20, |
| "min": 0, |
| "max": 18, |
| "t": 0, |
| "i": 6515 |
| }] |
| </code> |
| |
| ===== Editing POI ===== |
| |
| Now let's change the name and radius of the new POI: |
| <code> |
| https://hst-api.wialon.com/wialon/ajax.html?svc=resource/update_poi& |
| params={ |
| "itemId":50936, |
| "id":1, |
| "callMode":"update", |
| "n":"gurtam_office", /* change from "gurtam" to "gurtam_office" */ |
| "d":"poi", |
| "y":53.91069937030936, |
| "x":27.516643322771575, |
| "r":50, /* change from 100 to 50 */ |
| "f":1, |
| "c":16733440, |
| "tc":0, |
| "ts":20, |
| "min":0, |
| "max":18 |
| }&sid=<your_sid> |
| </code> |
| Response: |
| <code javascript> |
| [1, { |
| "id": 1, |
| "n": "gurtam_office", |
| "y": 53.9106993703, |
| "x": 27.5166433228, |
| "t": 0, |
| "i": 6515, |
| "e": 50676 |
| }] |
| </code> |
| |
| You can check how changes have been applied by making the request [[../apiref/resource/get_poi_data|get_poi_data]]. |
| |
| ===== Deleting POI ===== |
| |
| To delete a POI, use the request [[../apiref/resource/update_poi|update_poi]]: |
| <code> |
| https://hst-api.wialon.com/wialon/ajax.html?svc=resource/update_poi& |
| params={ |
| "itemId":50936, |
| "id":1, |
| "callMode":"delete" |
| }&sid=<your_sid> |
| </code> |
| Response: |
| <code javascript> |
| [1, null] |
| </code> |