Get BeckendlessUser who executes a API call

Consider I’m using a custom Hosted Script with a function to let the user retrieve a newsfeed.

i.e.:

public List<FeedObjects> getFeed(){
return Backendless.Data.of(Newsobject.class)
}

Of course there is a Relation between UserObjects and FeedObjects.
Generalized, I need to filter the Newsobjects by UserObject with a simple SQL Statement.

Is there a possibility to get the BackendlessUser who is executing the getFeed() method inside the Hosted API Service code? (without sending a UserObject from the client)

The User is of course logged in.

I consider there might be a way to accomplish this because there are also possibilities to restrict API calls to certain users or user roles.

Hi. I think it will help https://backendless.com/documentation/users/js/users_get_current_user.htm
Regards,
Kate.

Hey,

not sure if i made myself clear.
I’d like to fetch the user “inside” my server side code, it’s not a client side operation.

I’ve tried out your suggestion.

Both functions return null:

public BackendlessUser getCurrentUser(){
    return Backendless.UserService.CurrentUser();
}


public String getCurrentUserId(){
    return Backendless.UserService.loggedInUser();
}

You can pass userid as an argument to the method and then retrieve the user with:

BackendlessUser user = Backendless.Data.of( BackendlessUser.class ).findById( value );

We’re also looking into alternative ways to retrieve the logged in user.

Regards,
Mark