How to: Find a user using UserAPI


How do we supply a parameter to the userApi.findUsers API, with it being optional. For example, the loginAllowed or external parameters. Is the way we are doing it with True or False the way to do it? If we don't provide anything, it does not work, and we would like it to return internal and external users.

Would the recommendation be then to use the REST API, and not the built-in APIs?

We have the following code, which is able to find a single user but does not allow any sort of wildcard search. * or %.

Even though the documentation says the fields are optional, we are not sure how to specify an optional date or string. When we leave it out, it complains.

from java.util import Calendar, Date, TimeZone, Locale;

yearAgo = Calendar.getInstance()
yearAgo.add(Calendar.DAY_OF_MONTH, -365)

users = userApi.findUsers( "", "Liss, Russell", True or False, True or
False, yearAgo.getTime(), Date(), 0, 100 )

print( users )

for user in users:
print( user.fullName + " (" + + ") " + str( user.lastActive ) )


If you are actually putting this True or False in a boolean parameter in the API they are sending True because True or False is a Jython condition that evaluates to True in Java. It is Boolean so likely needs to be None in Jython to translate to null in Java.

Also, you will only be going to find users with email = and fullName = Liss, Russell which we believe will only match one result. The suggestion from our team would be to send None for those fields too assuming that want all users.

Steps to Follow

Use the following updated code to get the Users:

# List<UserAccount> findUsers(String email, String fullName, Boolean loginAllowed, Boolean external,
Date lastActiveAfter, Date lastActiveBefore, Long page, Long resultsPerPage)

from java.util import Calendar, Date, TimeZone, Locale;
yearAgo = Calendar.getInstance()

print yearAgo.getTime()

yearAgo.add(Calendar.DAY_OF_MONTH, -365)

print yearAgo.getTime()

allUsers = userApi.findUsers(None, None, None, None, None, None, None, None)

print "Found {0} total users".format(len(allUsers))

usersActiveAfterYearAgo = userApi.findUsers(None, None, None, None, yearAgo.getTime(), None,
None, None)

print "Found {0} users active after a year ago".format(len(usersActiveAfterYearAgo))

Related Information


Was this article helpful?
0 out of 0 found this helpful



Please sign in to leave a comment.