Erroneous documentation: finding a User by email doesn't work as expected
Hi Intercom team!
The documentation is misleading regarding how to find a User by email.
Version info
- intercom-java version: 2.8.0
- Java version: 8
Expected behavior
According to the documentation, User.find(ImmutableMap.of("email", someEmail)) should return data for an existing User, or null if no User is found, in the same way as User.find(ImmutableMap.of("user_id", someId)) does.
Actual behavior
User.find(ImmutableMap.of("email", someEmail)) returns a User object containing no data. When debugging, we can observe the the result returned by the API is a collection of users rather than a single user, and that the attempt made by the library to map this collection onto a User.class logically fails.
Workaround for the impatient
UserCollection result = User.list(ImmutableMap.of("email", userEmail));
List<User> page = result.getPage();
if (page.size() > 1) {
log.warn("Several users found for email {}", userEmail);
}
User user = page.isEmpty() ? null : page.get(0);
// do something with user
I thank you in advance if you can find some time to fix either the library or the documentation.
Regards, Nicolas
Same problem, a fix would b e much appreciated
I pinged Intercom about this specific issue - they confirmed to me that the SDK (and API) don't work as advertised. The API behaviour is correct, and the SDK/documentation needs to be updated to remove this. The workaround they suggested to me was to the same as Nicolas'.