GetAllEnabledUsers: Node.js example

 
var request = require('request');
 
companyKey = 'CompanyKey'; // Replace the Company Key
loginName = 'LoginName'; // Replace the Login Name
password = 'Password'; // Replace the Password
 
// Finding Swimlane
swimlaneFinderUrl = 'https://global.replicon.com/DiscoveryService1.svc/GetTenantEndpointDetails';
swimlaneFinderJsonBody = {};
tenant = {};
tenant['companyKey'] = companyKey;
swimlaneFinderJsonBody['tenant'] = tenant;
 
swimlaneFinderJsonBody = JSON.stringify(swimlaneFinderJsonBody);
 
// Using Discovery Call to get the Swimlane info of the Company Key
request({
 
uri: swimlaneFinderUrl,
method: 'POST',
headers: {'Content-Type' : 'application/json'},
body: swimlaneFinderJsonBody,
timeout: 10000
}, function (error, response, body) {
 
if (error) {
 
console.log('Error:', error);
} else if (response.statusCode != 200){
 
console.log('Error:', response.body);
 
} else {
 
swimlaneJsonBody = JSON.parse(body);
 
swimlane = swimlaneJsonBody.d.applicationRootUrl;
console.log('Swimlane:', swimlane);
 
allEnabledUserUrl = swimlane + 'services/UserService1.svc/GetEnabledUsers';
 
jsonBody = JSON.stringify({});
 
// All Enabled Users Web Service Call
request({
 
uri: allEnabledUserUrl,
method: 'POST',
headers: {'Content-Type' : 'application/json'},
auth: {
 
                    user: companyKey + '\\' + loginName,
                    pass: password
          },
body: jsonBody,
timeout: 10000
}, function (error, response, body) {
 
if (error) {
 
          console.log('Error:', error);
} else if (response.statusCode != 200) {
 
          console.log('Error:', response.body);
} else {
 
          enabledUsers = JSON.parse(body)
 
          for (i=0; i<enabledUsers.d.length; i++) {
 
                    console.log(enabledUsers.d[i]);
          }
};
});
};
});