Title / Description
Code /* 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 ); })();
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code