Retrieving user lookups via the user service

Hi there. How can user lookups be retrieved via a call to the user service?

I’m storing a lookup for created users at the time they are created using the system/user service and supplying a value for user_lookup_by_user_id in the related array. I need to be able to get this value when the users login - meaning I need to use the user service.

I’ve tried calling user?related=user_lookup_by_user_id, user/profile?related=user_lookup_by_user_id and user/session?related=user_lookup_by_user_id but none of these options return the user lookups in the response body.

I’ve only been able to get the lookup key values using system/user but I don’t see this as a solution as non-admin users should not get access to the system services.

Thanks in advance.

Hi @adam_weaveware!

Well you can create a post-processing script that returns user lookups

HI @paulo.hgf1408, thanks for the response.

We did put a custom script in as a workaround - it just makes the appropriate GET call to /system/user?related=user_lookup_by_user_id and takes the user ID and lookup name as a parameter. I’ll try to remember to post the source later.

So, we created a script that decorates user lookups onto the user session. Here it is:

platform.api.get(‘user/session’, {}, function(sessionBody) {

var session = JSON.parse(sessionBody);

platform.api.get('system/user/' + session.id + "?related=user_lookup_by_user_id", {}, function(userBody) {
    
    var user = JSON.parse(userBody);
    
    session.lookups = user.user_lookup_by_user_id || [];

    event.setResponse(session);
  });

);

I hope this comes in useful to someone!

1 Like