PDA

View Full Version : Get user via the API


nickh
04-29-2009, 07:52 PM
Hi folks. Is there a way to use the vBulletin API to find a user based on their username, or must I search the "users" database table? If there is, would you mind pointing me at some docs, or including a code snippit?

Thanks,
Nick

Lynne
04-29-2009, 08:30 PM
Did you look at the API - http://members.vbulletin.com/api/ ? There is a function called fetch_userid_from_username listed on there.

EnIgMa1234
04-29-2009, 08:38 PM
You can use the function above in conjunction with fetch_userinfo get the the full info

nickh
04-30-2009, 03:05 AM
Ack, I worded my question incorrectly.

I did indeed see fetch_userid_from_username() and fetch_userinfo(). However, those can only be used to get a user's info. Once you have that info, it's not possible to update it. Correct?

Using the vB API, is it possible to get a "user object", through which the user's data can be updated? For example:

$user = some_fetch_function($a_user_name);
$user->password = 'something new';
$user->save();

Thanks,
Nick

Dismounted
04-30-2009, 07:08 AM
You can pass it onto the user data manager. (See the manual about data managers.)

nickh
04-30-2009, 03:28 PM
Did you look at the API - http://members.vbulletin.com/api/ ? There is a function called fetch_userid_from_username listed on there.

You can use the function above in conjunction with fetch_userinfo get the the full info

Actually, I don't think this is possible. fetch_userid_from_username() is in admincp/usergroup.php , which isn't meant to be loaded using require() .

Other than querying the users database table, is there any other way to get a user's ID via their username?

Thanks,
Nick

Lynne
04-30-2009, 03:36 PM
fetch_userinfo is in functions.php.

You can always copy functions to your plugins if you need them.

nickh
04-30-2009, 03:42 PM
Right, but fetch_userinfo() is only useful if one has the user's ID.

For many reasons, copying functions is not a good idea. Doing so violates the DRY principle, makes your code brittle with respect to vBulletin updates, etc. Also, it negates the whole point of having an API.

Lynne
04-30-2009, 03:52 PM
Then all I can suggest is a quick query. I know that's what I do in some of my customized site code.

nickh
04-30-2009, 04:56 PM
Thanks for your insight, Lynne. It's helpful to hear what others have done in the past.