I'm trying to update a user with an externalId based on the Google Admin SDK documentation.
UserExternalId externalId = new UserExternalId();
externalId.setType( "account" );
externalId.setValue( "test" );
User user = new User();
user.setExternalIds( externalId );
try {
User update = directory.users().update( "USERKEY", user ).execute().setExternalIds( externalId );
LOGGER.info("Response from google: " + update.toPrettyString());
User full = directory.users().get( "USERKEY" ).setProjection( "full" ).execute();
LOGGER.info( "Response from new get user: " + full.toPrettyString() );
} catch (IOException e) {
LOGGER.info("Error: " + e);
}
When logging the response on the update call I can see that externalId is filled in and no errors are thrown. When I try to get the same user there is no trace of the externalId.
When I use Google' APIs explorer and fill in the ExternalId there I get the same behavior. It looks like the Google API is accepting the update request but is ignoring the ExternalId. What is the correct way to add an externalId to a user?
edit:
SGC's answer helped me out. The setExternalIds method expects a list of ExternalIds, I forgot to do this. The Google Java Directory API seems to return a json object when fetching externalIds, so it is necessary to parse it to read it.