Forum Discussion

radhika_kundana's avatar
3 years ago

Grouphubs: How to remove Role using api

Hi,

I would like to remove/add group hub roles(owner/member) to a user on clicking of a button. 

But V1 api mentioned in docs isn't working, can anyone guide the mistake in below request: 

https://community.lithium.com/restapi/vc/groups/id/grouphubID/roles/name/rolename(owner/member)/users/remove?role.user=/users/login/username

  • Hello radhika_kundana,
    Kindly use below v2 call to remove/add a role for a user from/to group hub:

    PUT https://{community-domain}/api/2.0/users/<user.id>
    Headers:
    Content-Type - application/json
    Body:
    { "data":{ "type":"user", "roles_to_remove":["g:<grouphub-id>:<Member/Owner>" ] } }

    In case you want to add a user just change the body parameter from roles_to_remove to roles_to_add.

    Here is the doc you can take a look: https://developer.khoros.com/khoroscommunitydevdocs/docs/remove-a-role-from-a-user

    Hope that helps.

    Regards,
    Abhishek Gupta

  • Hello radhika_kundana 
    For your first question, Why below call is not working:

    https://community.lithium.com/restapi/vc/groups/id/<grouphub-id>/roles/name/<Member/Owner>/users/remove?role.user=/users/login/<username>

    Because you were using groups instead of grouphubs, even if you use grouphubs it will not work. Because grouphub is a new feature and not being added to v1 calls mostly.

    Now the only option we have is v2 call and this call can be made from an Administrator and that's very sensible because other users should not have access to remove anyone's roles from grouphub.

    So i would suggest you add this call to a button and Display the button to admins only .

    Hope that helps.

    Regards,
    Abhishek Gupta

  • Hello radhika_kundana,
    Kindly use below v2 call to remove/add a role for a user from/to group hub:

    PUT https://{community-domain}/api/2.0/users/<user.id>
    Headers:
    Content-Type - application/json
    Body:
    { "data":{ "type":"user", "roles_to_remove":["g:<grouphub-id>:<Member/Owner>" ] } }

    In case you want to add a user just change the body parameter from roles_to_remove to roles_to_add.

    Here is the doc you can take a look: https://developer.khoros.com/khoroscommunitydevdocs/docs/remove-a-role-from-a-user

    Hope that helps.

    Regards,
    Abhishek Gupta

    • AbhishekGu First, I tried API v2 but its working only for community manager and not for other users.

      It shows permission denied for other users. 

      Here is my code: 

      <#assign uid = user.id?number />

      <#assign changeRole = restBuilder()

          .method("PUT")

           .path("api/2.0/users/${uid}")

          .body({

           "data": {

          "type": "user",

          "roles_to_remove": ["g:${groupID}:Owner"],

           "roles_to_add":    ["g:${groupID}:Member"]

            }

          }) />

       <#assign resp = changeRole.call() /> 

  • Hello radhika_kundana 
    For your first question, Why below call is not working:

    https://community.lithium.com/restapi/vc/groups/id/<grouphub-id>/roles/name/<Member/Owner>/users/remove?role.user=/users/login/<username>

    Because you were using groups instead of grouphubs, even if you use grouphubs it will not work. Because grouphub is a new feature and not being added to v1 calls mostly.

    Now the only option we have is v2 call and this call can be made from an Administrator and that's very sensible because other users should not have access to remove anyone's roles from grouphub.

    So i would suggest you add this call to a button and Display the button to admins only .

    Hope that helps.

    Regards,
    Abhishek Gupta