add role to user via rest API
Hi all,
We're running into an issue, that we cant seem to solve. We are trying to add a role to a user via the rest api, which works great on our staging environment, but on production does not work. We have an endpoint with a macro, which is invoked via an ajax call to pass in the neccessary valaues and do the proper error checking. This is the gist of the problem point in our code:
<#attempt> <#-- Add the role to the user --> <#assign addRole = restadmin("/roles/id/${roleID}/users/add?role.user=id/${user.id}") /> <#recover> <#-- Provide Generic error message --> {"status": "error","msg": "Something went wrong, please try again, error code 3"} <#return> </#attempt>
Im not sure what the issue is, as this works fine in our staging environment, but just not on production. The proper role IDs have been checked as well as user.ids. Just curious if anyone knows of something that we're leaving out for a production envrionment.
thanks,
Tri
Turns out the issue was user error. The problem was in the reference to the user.id in the call:
<#assign addRole = restadmin("/roles/id/${roleID}/users/add?role.user
=id/${user.id}") /> The API expects a computer readable number, with no commas. The above does not provide that if you have a large user id. Solution was to use this to strip the comma from user ids:
<#assign addRole = restadmin("/roles/id/${roleCheck}/users/add?role.user=id/${user.id?c}") />