$LW->read() for Users

Hello,

In a custom module, I am trying to read() data from users. Here’s a simplified version of what I’m trying to use, which consistently leads to no results.

$user_id = 2; // prefer current user but not sure how to obtain, so WW
$token = $_LW->getAuthToken($user_id);

$data_type = 'users';
$args = [];
$users = $_LW->read($data_type, $args, $token);
if (empty($users)) {
  $_LW->logDebug('USERS - NULL'); // I keep getting this 
}
else {
  $_LW->logDebug('USERS - SOMETHING');
}

As shown, I’ve tried to make use of $token should user data need an authorized request. API documentation suggests that it is possible to get a token in custom modules using getAuthToken. The documentation suggests passing $user_id, which I assume is the id of a given user. I’ve tried mine and WhiteWhales as hardcoded values. I’m not sure how to get the current user’s ID, nor whether the simple id (2, 7, etc) is what is needed here.

Likewise, the documentation for read() suggests that it is possible to get ‘users’ data with it. Perhaps it isn’t.

Else, perhaps I’m just missing one little detail, like the type isn’t users but lw_users or something. -_-’

Is this possible, and if so, what might I be missing?

Thanks,
Nick

Hi Nick,

I see – I apologize, I typo’ed when writing the documentation for $_LW->read(). In its current form, read() essentially acts as a PHP wrapper around the /live/json/data_type endpoint. If you log in to LiveWhale and check /live/json/users from your browser, you’ll see there’s not currently an endpoint there (there’s no public “Users” widget to run the onJSON function from currently). I’m sorry for that miscommunication, I’ve fixed that in the docs.

I think that means currently, if you have a need to pull a list of users in custom code, you’ll need to use the dbo object instead of read(), like this example which loops through all users in a specific group:

foreach($_LW->dbo->query('select', 'id', 'livewhale_users', 'livewhale_users.gid='.(int)$gid.' OR (livewhale_users.switch_groups IS NOT NULL AND FIND_IN_SET('.(int)$gid.', livewhale_users.switch_groups))')->run() as $res2) {
	// find all users in group $gid
};

Hello Karl,

That would be it. I knew there had to be some detail or assumption that wasn’t right.

Resorting to DBO again, here we go. Thanks Karl (and :partying_face:).

Thanks,
Nick