Forum Discussion

triSolutionFuse's avatar
10 years ago

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

 

  • triSolutionFuse's avatar
    triSolutionFuse
    10 years ago

    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}") />

  • triSolutionFuse - Have you tried adding this on production by adding this code in the firebug console? AFAIK this seems to be related to a config change required on production, if you hit this on production in firebug console, check for the error you get.

     

    We got into a similar situation with one such customization. Here is what we did to fix it.

     

    Opened a case with Lithium Support:

     

    We pushed the changes on production but while verifying, got an issue, “Calls to modify methods are not allowed when user is authenticated using session cookie.” in one of our customizations. So I have rolled-back the changes currently. We are not getting it on stage, I re-verified that. I looked into the lithosphere and got this article, https://community.lithium.com/t5/Developers-Discussion/Calls-to-modify-methods-are-not-allowed-when-user-is/m-p/125219/highlight/true#M4713

     

    Could you please enable this on production so we can use this custom feature so I can push the changes again? Please do this on priority.

     

    So, I'd suggest you to open a ticket with support with the error you are getting in console.

     

    I hope this helps.

    • triSolutionFuse's avatar
      triSolutionFuse
      Mentor

      Thanks VarunGrazitti for that tip. I've reached out to Support to see if this is something they need to enable. Will update of any relevant info.  Thanks again.

      • triSolutionFuse's avatar
        triSolutionFuse
        Mentor

        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}") />