Assigning a Role to a User¶
Description¶
This operation assigns a new role to a user.
This functionality can be used only in CloudCode (Java, JS or Codeless), 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. It is important the REST API is used with the CloudCode API key.
Method¶
POST
Endpoint URL¶
https://api.backendless.com/<application-id>/<CLOUDCODE-api-key>/users/assignRole
where:
Argument | Description |
---|---|
<application-id> |
The ID of your application generated upon its creation. You can obtain the value in the Manage > App Settings section of the Backendless Console. |
<CLOUDCODE-api-key> |
CloudCode API key of your application. You can obtain the value in the Manage > App Settings section of the Backendless Console. |
Request Headers¶
Content-Type:application/json
where:
Argument | Description |
---|---|
Content-Type |
must be set to application/json . This header is mandatory. |
Request Body¶
{
"user" : user-value,
"roleName" : roleName-value,
}
where:
Argument | Description |
---|---|
user-value |
user identification. A value for the property marked as identity. |
roleName-value |
name of the role to assign to the user account. |
Response Body¶
None.
Example¶
The example below assigns a new role "TrialUser"
to "alice@yourmail.com"
identity.
curl --location --request GET 'https://api.backendless.com/28066942-8273-BE6Q-AAD4-A1ZK34948E11/DCBACAA6-EF5B-49AA-8013-7BDF7A3A9A6B/users/assignRole' \--header 'Content-Type: application/json' \--data-raw '{"user": "alice@yourmail.com","roleName": "TrialUser"}'
CloudCode Codeless Reference¶
where:
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 а role that must be assigned. |
Important
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 "alice@yourmail.com"
has the following assigned roles:
The example below assigns a new role "Team Leader"
to the "alice@yourmail.com"
identity.
The result of this operation is a new assigned role "Team Leader"
: