a

Javascript code posted by a
created at 02 Dec 16:49

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
  Session IDs always expire after 24 hours. Use the SessionRecreate
  action to prolong your live session and never store your username and
  password.
*/
// Crude Admin API client:
var onsipApiRequest = function (data, load) {
  var onsipApi = new XMLHttpRequest();
  onsipApi.open('POST', 'https://api.onsip.com/api');
  onsipApi.addEventListener("load", function (event) {
    load(JSON.parse(onsipApi.response));
  });
  onsipApi.send(data + '&Output=json');
}
// Step 3: Notice the new session ID.
var sessionRecreated = function (response) {
  var sessionId = response.Response.Context.Session.SessionId;
  console.log(['New Session ID', sessionId, response]);
};
// Step 2: Get the session ID and call "SessionRecreate".
var sessionCreated = function (response) {
  var sessionId = response.Response.Context.Session.SessionId;
  console.log(['Current Session ID', sessionId, response]);
  onsipApiRequest(
    'Action=SessionRecreate&SessionId=' + sessionId,
    sessionRecreated
  );
};
// Step 1: Create a session.
(function () {
  var username = '******';
  var password = '******';
  var data = 'Action=SessionCreate';
  data += '&Username=' + encodeURIComponent(username);
  data += '&Password=' + encodeURIComponent(password);
  onsipApiRequest(
    data,
    sessionCreated
  );
})();
1.31 KB in 3 ms with coderay