Skip to main content
Contributor ⭐️
June 24, 2020
Solved

Can you add or change the Custom role though an API?

  • June 24, 2020
  • 13 replies
  • 620 views

I need to change the Custom Role for a large group of users, I like to do this through a scripted API call.

No it looks like that the Custom Role is not a field that you can use to fetch users and you also can’t add or change that filed.

 

Or am I doing something wrong and do I need to read better :)

iMac-van-Ron:python ron$ curl -H 'Authorization: Bearer <TOKEN>' -X PUT https://api2-eu-west-1.almostinsided.com/user/{UserID}/role/'Extreme Hero'
This action is only available for fields:email,oracle_sso_id,token_sso_id,openidconnect_sso_id,facebook_sso_id,janrain_sso_id,saml_sso_id,linkedin_sso_id,username,oauth2_sso_id,avatar

 

/Ron

 

 

    Best answer by daniel.boon

    @RonH @mstone 

    It’s now possible to remove custom user roles via API :) https://api2-eu-west-1.insided.com/docs/user/#operation/revokeRole

    13 replies

    daniel.boon
    Helper ⭐️⭐️⭐️
    June 26, 2020

    Hey @RonH!

    It’s not currently possible to update the custom user roles of a user via API, or to remove a custom user role from a user via API.

    However, it is possible to add custom user roles via API: https://api2-eu-west-1.insided.com/docs/user/#operation/addRole. You can achieve this by passing the custom role name into the user role object.

    inSided product alumnus
    RonHAuthor
    Contributor ⭐️
    June 26, 2020

    Hey Daniel,

    Thanks for the reply.

    I tried that and it give me a “Done” but nothing changes in the user settings

     

    iMac-van-Ron:~ ron$ curl -H 'Authorization: Bearer <TOKEN>' -X POST https://api2-eu-west-1.almostinsided.com/user/{userID}/role -d {"data":{-"user_role":["Extreme Hero"]}}

    #Done

    In the user data I only see:

    "roles":[{"auth_item":{"name":"roles.registered","main":true}}]

    and not what I expected:

    "roles":[{"auth_item":{"name":"roles.registered","main":true}},{"auth_item":{"name":"Extreme Hero","main":false}}]

     

    /Ron

     

    mstone
    Helper ⭐️
    June 29, 2020

    @daniel.boon any plans for allowing for the removal of a custom role via API? Use case being: user x was a customer, but is not longer a customer and as a result should be removed from the ‘customer’ custom role. 

    tom.shaddock
    Gainsight Employee ⭐️⭐️
    June 30, 2020

    Hey @RonH hmm yep your call looks ok - i think there could be something going on here with this specific end point unfortunately as im also unable to update the user role via API on one of our test environments too. I’ve opened a technical investigation internally into this which im sure will be immediately picked up, once I have some more information regarding it i’ll let you guys know!

    daniel.boon
    Helper ⭐️⭐️⭐️
    June 30, 2020

    @daniel.boon any plans for allowing for the removal of a custom role via API? Use case being: user x was a customer, but is not longer a customer and as a result should be removed from the ‘customer’ custom role. 

    We have no concrete plans for this at the moment @mstone, but it makes complete sense :)

    inSided product alumnus
    tom.shaddock
    Gainsight Employee ⭐️⭐️
    July 20, 2020

    Hi @RonH I was wondering if can you try this again? Can you just check your payload looks like this:

    {
    "data": {
    "user_role": [
    "tester"
    ]
    }

    Example uri: POST /user/329/role

    Also can you just ensure that the ‘Content-Type’ in the header is set to: ‘application/json’ else the endpoint will not know what to do with the payload else :slight_smile:

    Let me know how it goes!

    daniel.boon
    Helper ⭐️⭐️⭐️
    September 14, 2020

    @RonH @mstone 

    It’s now possible to remove custom user roles via API :) https://api2-eu-west-1.insided.com/docs/user/#operation/revokeRole

    inSided product alumnus
    Contributor ⭐️
    November 20, 2020

    Hi

    @daniel.boon I tried to use 

    https://api2-eu-west-1.insided.com/docs/user/#operation/revokeRole

     

    DELETE https://api2-eu-west-1.almostinsided.com/user/22005/role/Summit

    and got response 404

     

    roleName “Summit” and userId obtained from fetch user request and also exists in UI. Adding role works.

     

    Can you help?

    daniel.boon
    Helper ⭐️⭐️⭐️
    December 2, 2020

    Hi

    @daniel.boon I tried to use 

    https://api2-eu-west-1.insided.com/docs/user/#operation/revokeRole

     

    DELETE https://api2-eu-west-1.almostinsided.com/user/22005/role/Summit

    and got response 404

     

    roleName “Summit” and userId obtained from fetch user request and also exists in UI. Adding role works.

     

    Can you help?

    Just to close the loop for anyone else who was interested: revoking roles should now be working as expected via the endpoint

    inSided product alumnus
    Helper ⭐️⭐️
    July 21, 2021

    @daniel.boon - are we able to revoke roles with spaces? For example “Supported User” is one of our roles. I am able to apply the role with the POST command, but cannot delete the role. I have tested with single-word roles and my code works in that case.