Log in
To utilize the DataCloud API we need to obtain a session ID. This ID will be used for all future calls that we make.
First, obtain the username and password from a form on the page. In this case use the jquery selector to grab the two fields with the class .dsuser and .dspass.
var dsuser = $('.dsuser').val();
var dspass = $('.dspass').val();
Then construct the data body to be sent to the rest call.
var dataObj = 'username=' + dsuser + '&password=' + dspass;
We will then call the function that will make the rest call. We need to specify a response handler. In this case it is hdlLogin.
The call to the function:
restCall('login', 'POST', dataObj, hdlLogin, hdlLogin);
The function definition:
var restCall = function(methodCall, type, requestData, response, responseHandlerFailure) {
var reqObj = {
url: 'https://datacloud2.pervasive.com/cloudrest/' + methodCall,
method: type,
requestData: requestData,
requestHeaders: {
Accept: 'application/xml',
},
onSuccess: responseHandler,
onFailure: responseHandlerFailure
}
sforce.connection.remoteFunction(reqObj);
}
The response handler "hdlLogin()" is defined as:
var hdlLogin = function(data) {
var jsondata = eval("(" + data + ")");
if (jsondata.success == 'false') {
//handle failed login
} else {
//store off the sessionid for future calls
sessionId = jsondata.sessionId;
//handle successful login
}
}
Last modified date: 12/17/2021