I am trying to call the API and create users. I have created two roles Role 1 and Role 2. For some users I want to assign Role 1 and for some users Role 2. The use case is something like my application will have vendors and customers. From the vendor app the default role for user registration should be role 1 and for customer app it should be role 2. I tried different methods mentioned in the forum but nothing works.
I tried the script on Post process, tried sending a post request to /user/register?role_id=2 and other stuff too but nothing seem to be working. I tried this post as well https://blog.dreamfactory.com/adding-users-to-your-dsp
Can someone give me a link or tell me the procedure on creating users with different roles using API?
Hi @juniorconte users have to register by themselves not by an admin.
Letâs say there are two mobile apps for my company where the customers register themselves and raise certain requests. There is another mobile app which the vendors use to accept the requests raised by customers. So when the user gets registered from customer app they should be assigned customer role where as it will be vendor role for the other mobile app. Hope this makes sense.
I am not sure whether platform.session.user will be available for the first time registration? Correct me if i am wrong because I tried to get the user id using platform.api.get(âuser/sessionâ).user_id but it says âThere is no valid session tokenâ
One curious thing I have noticed is a POST request made directly to âsystem/userâ with âuser_to_app_to_role_by_user_idâ : { âapp_idâ: 1, ârole_idâ: 1} in the user details payload is working perfectly fine and the user is being created with exact assignment of roles.
This whole system/user and user/register is quite confusing to me and I am not sure which one to use.
I think there is a session, as in the request, the user/73 âas the error log that have attachedâ was created in the registration request.
I think the problem is to allow the user to request this system / user via the API. He could to set permissions that should not have access. The user / register prevents it.
I have setup a role as you have mentioned and assigned it to Open registration default role. Also created an app with this default role. Now, I have made the following API call.
I have also tried printing the event.response and also the Patch event result. The response says platform.session.user is null. I am not sure why but in my case platform.session.user is returning null instead of the id of the user.
There is something strange about the user.register.post.post_process. Even putting something simple like: event.response.content.foo = âbarâ; foo does not return to the request.
Making a var_dump (event.response.content); foo value appears on the console âtail -f âŚ/apps/dreamfacotry/htdocs/storage/logs/dreamfacotry.logâ . The same thing happens if I do a var_dump (platform.session.user)
I will investigate further, and any news notice here. If I get to conclusion which is really a bug, I will open an issue in Git Hub.
I am not sure about changes to event.response not sticking. I was able to set event.response.resp_check = true; statement and when I return the event.response resp_check was there intact in the response printed in console.
The problem I have is about the platform.session.user and the patch event. For me platform.session.user returns null and not working because I have setup a check inside the if loop if(!!platform.session.user) which is not going through whereas the above resp_check is set outside the loop and this is being set successfully.
So, event there is a bug with platform.session.user being null while the time of registering in the POST process script.
@juniorconte
Did you find any solution for this bug? Iâalso have been implemented it in my script tab. Actually i think that trouble arises while we calling this platform.api.get('system/user/'+platform.session.user.id+'?related=user_to_app_to_role_by_user_id');
api itâs really not get the userObject in case of failure it returns undefined value. I have tested these api calls via post man itâs working.
@formerstaff Can you say the trouble(error) of @juniorconte solution of this post.
If you say the suggestions(any other solutions for role assignment via api) then itâl be useful us as go through DSP faster in our development.
@juniorconte When changing the content of the response you will need to set event.response.content_changed = true before it will get copied back to the main process stream. This was to prevent copying content unnecessarily when handling events. See if that helps this scenario. We have someone looking into the big picture question right now.
I wonder if the idea of spending login = true for user / register, should create a valid session during post_proccess the user request / register. That still does not fuincionou correctly, apparently the role is not applied correctly.
Ok, we have to check all the settings, but we know that is not a platform BUG.
Here a few hours, I will prepare a material comprising all config points in detail.