How can I pass a username from another website to elgg and by calling get_user_by_username(username) and user->guid get guid of that user and pass it back to the first website using elgg web services?
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by Raül Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Evan Winslow@ewinslow

Evan Winslow - 0 likes
- Gerard@gkanters

Gerard - 0 likes
- Gerard@gkanters

Gerard - 0 likes
- Gerard@gkanters

Gerard - 0 likes
You must log in to post replies.Have you looked at http://learn.elgg.org/en/latest/guides/web-services.html already?
In the default web services there is no such function. There is plugin which is unfortunately a bit old with a lot of deprecated functions but it still works https://github.com/markharding/elgg-web-services
You could use the http://yourwebsite.com/services/api/rest/xml?method=user.get_user_by_email
But I have no idea how to pass the email parameter that is required. I modified that function so it returns the username of the logged in user, but I think that is not what you are looking for.
I think that passing parameters is broken in elgg web_services, but I am not sure.
I tried adding ?email=addres@test.com
which is usually the method on how to pass parameters.
No, it is not broken. Passing additional parameters must be done with &
So if you add the function below you can get a username with the following url:
http://yourwebsite.com/services/api/rest/xml?method=user.get_user_by_username&username=test
/**
* Web service to get a user registered with an user ID
*
* @param string $username to check for
*
* @return string $founduser the name of the user
*/
function user_get_user_by_username($username) {
if(!$username){
$user = elgg_get_logged_in_user_entity();
} else {
$user = get_user_by_username($username);
}
if (!$user) {
throw new InvalidParameterException('registration:usernamenotvalid');
}
$founduser = $user->username;
return $founduser;
}
expose_function('user.get_user_by_username',
"user_get_user_by_username",
array('username' => array ('type' => 'string', 'required' => false)
),
"Get Username by username",
'GET',
false,
false);
But to be honest, this function seems a bit silly.