menu
Login
Authenticate User

Sample Javascript code to login to VSETA Cloud Services.

Code OutputRESPONSE OUTPUT

                            [{
                               SessionToken: "0x00"
                            }]
                            
Tip: SessionToken is passed to other applicable APIs
Sample CodeJavascriptCopy

    //***** VSETA API ACCESS *****

    //Use Developer Account instead of Personal Account to avoid Session Termination.
    var userName = "dev.app@domain.com";
    var userCertificate = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX";

    //Your Organization’s APP API Account Key - Do Not Share your ID - Request a new ID if you require different API Permissions.
    var accessKeyId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX";

    //Add accessKeyId to User Login for Authentication
    var sessionToken = JSON.stringify([{
        "name": "username",
        "value": userName
    }, {
        "name": "usercertificate",
        "value": userCertificate
    }, {
        "name": "accessKeyId",
        "value": accessKeyId
    }]);

    //************************************


    /*GET A LIST OF USER SUBSCRIBED PROPERTIES*/
    $.ajax({
        type: "POST",
        dataType: "json",
        contentType: "application/json",
        url: "https://ai.vseta.com/auth/",
        data: sessionToken,
        success: function(data) {

            console.log('Auth Data: ' + JSON.stringify(data));

            var sessionToken;

            var propertyListSession = JSON.stringify([{
                "sessionToken": data[0].SessionToken
            }, {
                "accessKeyId": accessKeyId
            }])

            sessionToken = data[0].SessionToken;

        },
        failure: function(errMsg) {
            console.log('ERROR: ' + errMsg);
        }
    });
                    
Service
Multi-Property Service Data

Service Routine Data for Multiple Properties.

Code OutputHTML OUTPUT Tip: Copy below code into Sample HTML Template to view output.
HTML Code LibrariesHTMLCopy
-- =============================================
-- Author: VSETA Mobile Technologies Inc.
-- Create date: NOV 8th, 2021
-- Description: API Example - getDailyServiceAuditByPerson
-- Release: SUBSCRIBER ORGANIZATION USE ONLY - Do Not Share, Post, Send, Release and Print outside of your organization or without written permission from VSETA.
-- Copyright © 2021 VSETA Mobile Technologies and third-party contributors. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1) Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2) Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3) Neither the name of VSETA nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Visit vseta.com/legal for latest VSETA Terms and Conditions.
-- =============================================

Used Jquery JS: data-require="jquery@*" data-semver="2.1.4" src="https://code.jquery.com/jquery-2.1.4.js"
Bootstrap Style: href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css
Bootstrap Script: src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
Sample CodeJavascriptCopy

    //***** VSETA API ACCESS *****
    
    //Use Developer Account instead of Personal Account to avoid Session Termination.
    var userName = "dev.app@domain.com";
    var userCertificate = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX";

    //Your Organization’s APP API Account Key - Do Not Share your ID - Request a new ID if you require different API Permissions.
    var accessKeyId = "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX";

    //Add accessKeyId to User Login for Authentication
    var sessionToken = JSON.stringify([{
        "name": "username",
        "value": userName
    }, {
        "name": "usercertificate",
        "value": userCertificate
    }, {
        "name": "accessKeyId",
        "value": accessKeyId
    }]);

    //Start Date
    var startDate = "2021-03-11";

    //End Date
    var endDate = "2021-03-12";

    //************************************


    /*GET A LIST OF USER SUBSCRIBED PROPERTIES*/
    $.ajax({
        type: "POST",
        dataType: "json",
        contentType: "application/json",
        url: "https://ai.vseta.com/auth/",
        data: sessionToken,
        success: function(data) {

            console.log('Auth Data: ' + JSON.stringify(data));

            var sessionToken;

            var propertyListSession = JSON.stringify([{
                "sessionToken": data[0].SessionToken
            }, {
                "accessKeyId": accessKeyId
            }])

            sessionToken = data[0].SessionToken;

            /*GET SERVICE DATA FOR LIST OF SUBSCRIBED PROPERTIES*/
            $.ajax({
                type: "POST",
                dataType: "json",
                contentType: "application/json",
                url: "https://ai.vseta.com/getUserPropertySubscriptions/",
                data: propertyListSession,
                success: function(data) {

                    console.log('userSubscribedProperties Data: ' + JSON.stringify(data));

                    //Modify the SessionToken parameters according to VSETA API Documentation
                    var apiToken = null;
                    var apiTokenList = [];

                    /*CREATE ARRAY OF API TOKENS FOR EACH SUBSCRIBED PROPERTY*/

                    //console.log('userSubscribedProperties > sessionToken: ' + sessionToken);

                    for (var k = 0; k < data.length; k++) {

                        apiToken = JSON.stringify([{
                            "sessionToken": sessionToken
                        }, {
                            "propertyid": data[k].PublicPropertyId
                        }, {
                            "accessKeyId": accessKeyId
                        }, {
                            "startDate": startDate
                        }, {
                            "endDate": endDate
                        }])

                        console.log('apiToken: ' + apiToken);

                        apiTokenList.push(apiToken);
                    }

                    //URL: Modify URL according to VSETA API Documentation to access various subscribed Restful APIs.
                    //success: Success Returns JSON Array Object if accessKeyId is valid for the called Restful API resource.

                    /*
                        Notes:

                        Blank Data:

                        At times, You may see blank Room data which is due to no data being available for the given time/date period.
                        This can happen if a Room Sensor is offline for maintenance.

                        Full Column Names:

                        If time is near the beginning of the hour and not all Rooms have been updated yet, you may not see all of the column names
                        using this sample code. Store or reference the Room Names separately in your code.
                    */

                    for (var i = 0; i < apiTokenList.length; i++) {

                        console.log('apiTokenList ['+i+']'+ apiTokenList[i]);

                        var html;


                        $.ajax({
                            type: "POST",
                            dataType: "json",
                            contentType: "application/json",
                            url: "https://ai.vseta.com/getDailyServiceAuditByPerson/",
                            data: apiTokenList[i],
                            success: function(data) {

                                console.log('Data: ' + JSON.stringify(data));

                                if(data.length > 0){

                                    html = '';
                                    html += '';
                                    var flag = 0;

                                    $.each(data[0], function(index, value) {
                                        html += '';
                                    });

                                    html += '';

                                    $.each(data, function(index, value) {
                                        html += '';
                                        $.each(value, function(index2, value2) {
                                            html += '';
                                        });
                                        html += '';
                                    });

                                    html += '
' + index + '
' + value2 + '
'; $('body').append(html); } }, failure: function(errMsg) { console.log('ERROR: ' + errMsg); } }); } }, failure: function(errMsg) { console.log('ERROR: ' + errMsg); } }); }, failure: function(errMsg) { console.log('ERROR: ' + errMsg); } }); }