Assigning a Role to User

Getting Error while assigning a role to user using REST API

[HTTPStatusEvent type=“httpResponseStatus” bubbles=false cancelable=false eventPhase=2 status=401 redirected=false responseURL=“”]
{“code”:2002,“message”:“Version is disabled or provided wrong application info (application id or secret key)”}

my application id or secret key both are correct.
Thanks kinjal.

Hi Kinjal,

Please provide full information about the request: URL, method, headers list and body (if present). This way we could test it and verify which is the problem.

thanks for quick response.
URL ::
method = POST
header list = [
application-type: ‘BL’
req data :: {“user”:“0FEC7A20-F44B-0320-FF25-7018871AB700”,“roleName”:“RestrictedUser”}

The problem is that you’re using application-type for business logic and secret-key for REST.
If this is a request from your business logic, then change the secret key to the corresponding one.

If this is just your client’s REST request, then change application-type header to REST.

ok i changed it with REST. its worked got another error

[HTTPStatusEvent type=“httpResponseStatus” bubbles=false cancelable=false eventPhase=2 status=400 redirected=false responseURL=“”]
{“code”:2011,“message”:“Assign/unassign role is available only from server code”}

Well, the error message talks for itself: assigning roles is allowed only from business logic code. This is a matter of security, for users not to be able to assign roles to themselves.

actually i want to develop admin app. on which admin can handle all Users Role. can you please provide me any reference link ? so i can follow that and implement in my code.

Hi Kinjal!
For this purpose you can create Custom Event handler in Business logic. And invoke it via rest request.
This is doc how Business logic works

This is sample project with Custom Event handler. (Not forget to change your appid and business logic secret key in file and
You should run this project and invoke with following rest request:

curl -H application-id:xxx -H secret-key:xxx -H application-type:REST -H Content-Type:application/json -X POST -d '{"identity":"", "role":"test" }' [url=][/url]

As the result you receive assigned custom role to user with identity from request.
For testing you also can use console admin page

okay thanks let me follow your step then will get back to you.

Hello, when i tried to used this for assign User Roles through given your code’

curl -H application-id:xxx -H secret-key:xxx -H application-type:REST -H Content-Type:application/json -X POST -d '{"identity":"", "role":"test" }'[url=][/url]'

then in response getting empty object and can not see assigned User role at backendless console side.can you help me with that? i already created custom event at console side.

Getting empty object is expected - it means that request has been competed without errors.
How do you check if the role has been assigned?

One more thing: before executing request for assigning role make sure that custom servercode is deployed or is in debug mode. You can make it through Business Logic tab in console.

Hello, after getting empty object. i will move at backendless Console side->data->users->Table scheme and permissions->user permissions. on which i can not see permission for Particular User which is assigned by me through REST API call

Hello, i am using ActionScripts. how i need to do that?

Try the following: go to Data -> choose the target user ( click on checkbox near it ) -> click on button “User roles” on the top of the window. You’ll see a list of roles for this user. Assigned roles would be checked.

To start debugging code: open custom code project in IDEA, compile it and run ./ script from /bin folder.
To deploy code: same as for debugging, but run ./ script.
To check if code is in debug/deployed: navigate to Business Logic tab, choose “Custom events”, switch to Debug/Production tab. You’ll be able to see event in the list.

Hello, can not see checked for assigned roles.

Check again if the custom code is on production/debug.
Also you can change the custom event handler from the project you’ve received from Kate so it returns some value. This way you’ll be able to determine if the code has been executed correctly, or it’s not deployed at all. In the first case you’ll receive the value indicating success, in the second - you’ll get empty object.

from where i need to install IDEA?

You can download it from JetBrains site: