I want to display a WordPress logged in user ID and email in another website so, I'm using the wordpressjson-api plugin to create an api but it's not working.
When I hit a direct link, it displays data as:
"{\"id\":1,\"email\":\"[email protected]\"}"
But when I use json_decode and print data, it displays:
string(22) "{"id":0,"email":false}"
api code
public function get_loggedin_user_details() {
global $user;
global $wpdb, $json_api;
$current_user = wp_get_current_user();
$myObj->id = $current_user->ID;
$myObj->email = $current_user->user_email;
$logedin_userid = json_encode($myObj);
return $logedin_userid;
}


You are not authenticating your request, so the request is not logged, resulting in ID 0 and no email.
WP rest api provides a cookie authentication method, but there also plugins, you can read more on how-to here:
https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/