intercom-java
intercom-java copied to clipboard
No custom attributes are returned when creating an user + a company
Users can be created while also associating them with a company (as part of the same call). The response of this call contains a key called customAttributes
belonging to the companyCollection
, but this is always blank even if a bunch of custom attributes are specified.
The recommended way for viewing a company's custom attributes should be listing that company itself (that's how it also works with the plain REST API), but the Java SDK seems to be a bit confusing here. From my point of view, the company custom attributes should be removed from the response for creating an user (as that way it'll be consistent with the response received from a plain HTTP call). Alternatively, the response should just present the actual custom attributes that were passed in the call.
Version info
- intercom-java version: 2.3.3 (latest at the moment of writing this)
- Java version:
1.7.0_55
Evidence
Creating an user and associating it with a company:
String id = "20180607iii";
User user = new User().setUserId(id);
Company intercomCompany = new Company();
intercomCompany.setName("Java Company " + id);
intercomCompany.setCompanyID("co_" + id);
intercomCompany.addCustomAttribute(CustomAttribute.newStringAttribute("test_string", "testValue"));
user.addCompany(intercomCompany);
User outputUser = User.create(user);
System.out.print(outputUser);
Response of this call:
User{type='user', id='5b18f9167faf60dad73c3fdb', name='null', email='', phone='null', userId='20180607iii', avatar=Avatar{type='avatar', imageURL=null} io.intercom.api.Avatar@da2569c7, createdAt=1528363286, updatedAt=1528363286, remoteCreatedAt=0, unsubscribedFromEmails=false, sessionCount=0, lastRequestAt=0, signedUpAt=0, lastSeenIp='null', customAttributes={}, userAgentData='null', locationData=LocationData{type='location_data', city_Name='null', continentCode='null', countryCode='null', countryName='null', latitude=0.0, longitude=0.0, postalCode='null', regionName='null', timezone='null'} io.intercom.api.LocationData@3870608c, companyCollection=CompanyCollection{, totalCount=0} company.list{page=[Company{id='5b18f9167faf60dad73c3fdc', name='Java Company 20180607iii', companyID='co_20180607iii', sessionCount=0, monthlySpend=0.0, remoteCreatedAt=0, createdAt=0, updatedAt=0, plan=null, customAttributes={}, segmentCollection=SegmentCollection{} segment.list{page=[]} io.intercom.api.SegmentCollection@1d28d63a, tagCollection=TagCollection{} null{page=[]} io.intercom.api.TagCollection@3c1} io.intercom.api.Company@54b41f3c]} io.intercom.api.CompanyCollection@4ab0a80a, socialProfileCollection=SocialProfileCollection{type='social_profile.list', socialProfiles=[]} io.intercom.api.SocialProfileCollection@8311d4c, segmentCollection=SegmentCollection{} segment.list{page=[Segment{id='58ec3d7ef6f111ae22eee257', name='null', createdAt=0, updatedAt=0} io.intercom.api.Segment@21521a05, Segment{id='59f8305050ffdbf0d9f99bae', name='null', createdAt=0, updatedAt=0} io.intercom.api.Segment@986d348d]} io.intercom.api.SegmentCollection@e06b1b22, tagCollection=TagCollection{} tag.list{page=[]} io.intercom.api.TagCollection@cfc2de33, updateLastRequestAt=null, newSession=null, untag=null} io.intercom.api.User@1c5bc194
Steps to reproduce
Described in the Evidence section
Digging into this, the behaviour seen here isn't specifically limited to creating a new users and companies. If you make the same request with existing user_id and company_id values you will get the same output where the customAttribute is blank
String id = "existing_user_id";
User user = new User().setUserId(id);
Company intercomCompany = new Company();
intercomCompany.setName("Java Company " + id);
intercomCompany.setCompanyID("existing_company_id");
intercomCompany.addCustomAttribute(CustomAttribute.newStringAttribute("test_string", "testValue"));
user.addCompany(intercomCompany);
User outputUser = User.create(user);
// Output will have: customAttributes={}
outputUser
is created by parsing the response from the API. If you make a raw API request, the returned response does not include the full company information and doesn't not return custom attributes, so the SDK output is correct when it converts the API response to the outputUser
object
Summary
- The SDK is correctly parsing the output of the API
- But as the output of the API is not showing all information, it can be confusing as to why some input information is not returned in the resulting object
Possible workarounds
- Retrieving the company information in a separate API call and combining and replace the existing company in the
outputUser
object. As a user can have multiple companies and you can update multiple companies at once this would make more API calls and which would utilise part of the API quota that is part of the rate limits - Alternatively we could read all custom attributes that the user provided and add that to the companies of
outputUser
.