intercom-java icon indicating copy to clipboard operation
intercom-java copied to clipboard

Erroneous documentation: finding a User by email doesn't work as expected

Open ndemengel opened this issue 6 years ago • 2 comments

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

ndemengel avatar Jun 07 '19 08:06 ndemengel

Same problem, a fix would b e much appreciated

Khyme avatar Nov 13 '19 08:11 Khyme

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'.

rickerbh avatar Nov 21 '19 05:11 rickerbh