rbv_api.setSessionData()

Purpose

This function sets user session data as a key/value pair. The maximum number of key/value pairs is 50. If you set a value for an existing key, the new value overrides the previous value. See User session data API for more information about user session data.

Syntax

rbv_api.setSessionData(key, value);

Parameters

key

A string that is the lookup key for user session data. The maximum length of a key is 50 characters.

value

The value associated with key. The value can be a boolean, number, string (maximum length is 1000 characters), or null (where null is the value).

Return value

The success message "Session Data set successfully" or throws exception upon error. Exception messages include:

  • Empty Key Received! — No input was passed
  • Invalid Input — Input was in the wrong format
  • Limit Violation. Max Allowed: 50 keys reached — User has already stored the maximum of 50 key/value pairs

Example

The following example sets a key/value pair:

try {
  var key = "name1";
  var value = "Joe";

  var resp = rbv_api.setSessionData(key, value);
  rbv_api.println(resp); 

} catch (error) {
  rbv_api.println(error);
}

The following example passes a null key value and results in an error:

try {
  
  var value = "Joe";

  var resp = rbv_api.setSessionData(null, value);
  rbv_api.println(resp); 

} catch (error) {
  rbv_api.println(error);
}

The error information is printed to the console:

JavaException: com.rb.core.services.api.ApiException: Empty Key Received!