Skip to content

Instantly share code, notes, and snippets.

@ashmigelski
Created October 8, 2014 22:13
Show Gist options
  • Save ashmigelski/6093ee9b3c65a3e43803 to your computer and use it in GitHub Desktop.
Save ashmigelski/6093ee9b3c65a3e43803 to your computer and use it in GitHub Desktop.
Wialon + Node.js - Simple sample
var request = require('request');
var URL = 'https://hst-api.wialon.com/wialon/ajax.html?';
var SID = null;
function searchItems () {
var params = {
spec: {
itemsType: 'avl_unit',
propName: 'sys_name',
propValueMask: '*',
sortType: 'sys_name'
},
force: 1,
flags: 1,
from: 0,
to: 0
};
request.post({
url: URL + 'svc=core/search_items',
json: true,
form: {
sid: SID,
params: JSON.stringify(params)
}
}, function (error, response, body) {
console.log('Search items');
console.log(body);
logout();
});
}
function logout () {
request.get(URL + 'svc=core/logout&params={}', function (error, response, body) {
console.log('logout');
});
}
function login (user, password) {
var url = URL + 'svc=core/login&params={user:"' + user + '",password:"' + password + '"}';
request.get({
url: url,
json: true
}, function (error, response, body) {
console.log('login');
SID = body.eid;
searchItems();
});
}
login("wialon_test", "test");
@ashmigelski
Copy link
Author

$ npm install request before run script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment