Forum Discussion

omygoodness's avatar
8 years ago

How to get a role UID?

Hello,

I would like to add roles using api v1 but for this operation I need role UID.

I am trying to use post query which is here:
https://community.lithium.com/t5/Developer-Documentation/bd-p/dev-doc-portal?section=commv1&leaf-id=Role.users.add#Role.users.add

 

It looks like this:
http://community.lithium.com/community-name/restapi/vc/roles/id/[id] /users/add

 

For now I have "normal" ID of role but it is not working.

I get error: No role with the specified uid.

 

Is it possible to get UID of a role? 

 

3 Replies

  • omygoodness

    UID is something for lithium internal use, they do not expose them. Normal id will work here but it seems you are using a role id which does not exist.

    You can get all the role using below API

    http://community.lithium.com/community-name/restapi/vc/roles

    Check if the ID you are using exists or not. 

    Here is the call to add a role

    <#assign addRole = restadmin("/roles/id/${roleID}/users/add?role.user=id/${user.id}") />
  • omygoodness's avatar
    omygoodness
    Mentor
    8 years ago

    VikasB Role exists but I am trying to send post request with jquery and it didnt work with ID so I used role name instead and it is working now :)

     

    $.post('/restapi/vc/roles/name/RoleName/users/add?role.user=id/47')
    .done(function( data) {
    console.log(data); });

    I will try to use call in freemarker. Hope it will work 

  • VikasB's avatar
    VikasB
    Boss
    8 years ago

    omygoodness

    I agree that role exists but the ID you were using does not exist. It gives the error "No role with the specified uid" when the role id does not exist. See here

    It would work with the ID also (See here) only if you are login with an admin account otherwise it will return the below response either you are using role id or role name.  Even the rest call will return the same response in freemarker. 

    <response status="error">
      <error code="303">
        <message>
          User -1 does not have the following permission(s) at ecohaus: [ allow_analytics, allow_access_metrics ]
        </message>
      </error>
    </response>

    So you must use restadmin call to add the role. You can use endpoint to hit the restadmin call.