I made a bug report here https://drupal.org/node/2159483 for using query parameters in the url.

Is there someone who can tell me how a logged in user can get his user details or the uid of this user?

When I have the uid I can do the following:
http://example.com/user/4.json

Thanks!

Comments

Grayside’s picture

Are you asking how they can get it via the API or via Drupal?

Within the Drupal site, look for any links to edit the user account.

In the API generated, this is a gap. I think there needs to be a RestWS DX module that adds some of the middle bits like this, like a resource that redirects to the currently logged in user account.

timlie’s picture

I indeed want to get this through the restws api.

Alessandro Siletto’s picture

Following.

The /user.json endpoint is available only to administrator and get the list of all users.

I need some "whoami" function that given the session auth print the user details (I need the user id).

For now I wrote my own module with this extension

function mymodule_menu() {
  $items['restws/custom/whoami'] = array(
    'page callback' => 'mymodule_whoami',
    'access callback' => 'user_is_logged_in',
    'type' => MENU_CALLBACK,
  );
  return $items;
}

function mymodule_whoami() {
  drupal_add_http_header('Content-Type', 'application/json');
  global $user;
  $output = array(
	"uid" =>$user->uid,
	"name" =>$user->name,
	"mail" =>$user->mail,
	"roles" =>$user->roles
  );
  drupal_json_output($output);
  drupal_exit();
}