Setting user role with API

I am trying to register a new user with a defined user role. There is a post that says a script could be the solution, I messed around with writing a custom script, but didn’t get it to work
This post however indicates that it would be possible without writing a server side script, using the API as is.

I gave this role the permissions and role system access. The sessiontoken is also sent in the header of the request. The new user is made, but the role is still his default role. My DSP-version is 1.6.10.

Any help with this problem would be greatly appreciated.

I have not tested this in your DSP version. 1.6.10 is considered quite old now. Are you willing and able to use 1.8.2 and see if the problem remains?

Thanks for your reply. We use this DSP for a computer science project which is almost due, so I’m a bit reserved in case I would break the platform, and disable our team from continueing working. If the deadline permits it, I’ll certainly try to upgrade to a more recent version.

I have reviewed with our engineers, and we have a solution that almost works for your purpose.

POST /user/register?role_id=3 {"email":"user@domain.com", "password":"password123"}

Script  user.register.post.post_process

var user_id = event.response.id;
var role_id = event.request.body.role_id;
var result = platform.api.patch('system/user/' + user_id, JSON.stringify({"role_id":role_id}));

However, this will not work for updating the role of the user you just registered (the one to which the current session belongs). I don’t believe that can be accomplished without the ability to run a server-side script as a user other than the current one. There is a new feature request in the backlog to allow running server-side scripts as admin, but unfortunately that will not help you until the feature is released.

3 Likes