Skip to content

Unassigning a Role from a User


Users may have different roles, and in some cases you may want to unassign a specific role from the user by invoking the operation described in this topic.

This operation is available only from Custom Business Logic. Applications must use the "CloudCode API key" in order for the API call to be  accepted on the server. The reason for this restriction is that a malicious use of this API can easily compromise application's security. As a result, this API must be used from a controlled environment.


Non-blocking Method 1: With the Callback

The method call does not block - it returns immediately. The AsyncCallback argument receives either the response or the fault returned by the Backendless servers.

public void Backendless.UserService.unassignRole( String identity, 
                                                  String roleName, 
                                                  AsyncCallback<Void> callback );

Blocking API

public void Backendless.UserService.unassignRole( String identity, String roleName ) 
                                                            throws BackendlessException;


Argument                Description
identity value for a user property marked as identity. String value.
roleName the name of the role to remove from the user account. String value.
callback an object which receives either a return value or an error from the server. The class must implement the AsyncCallback<Void> interface.

Return Value



The example below unassigns a role "TrialUser" from the "" identity.

Non-Blocking API

Backendless.UserService.unassignRole( "", "TrialUser", new AsyncCallback<Void>()
  public void handleResponse( Void unused )
    // on success logic

  public void handleFault( BackendlessFault backendlessFault )
    // exception handling logic
} );

Blocking API

Backendless.UserService.unassignRole( "", "TrialUser" );

The following errors may occur during the API calls described above. See the Error Handling section for details on how to retrieve the error code when the server returns an error.

Error Code
Version is disabled or provided wrong application info (application id or secret key)
Could not find role.
One of the required parameters (user identity or roleName) is null.
Could not find user by id or identity.
Could not assign role to user.
Could not unassign role to user.

CloudCode Codeless Reference



Argument                Description
identity A value for a column in the Users table marked as identity. By default the column marked as identity isemail, however, it can be changed to another column in Backendless Console.
role name The name of the role to be unassigned from the specified identity.


This Codeless block is only available in CloudCode due to the security reasons. If this operation is exposed to users, then your application can be compromised.

This operation does not return a value.

Consider the following record in the Users data table:


Suppose, the identity "" has the following assigned roles:


The example below unassigns the "Team Leader" role from the ""identity.


After the Codeless logic runs, the "Team Leader" role gets unassigned: