Skip to main content
Contributor ⭐️
Jun 24, 2020 2:38 PM UTC
Solved

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

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

 

 

    daniel.boon
    Helper ⭐️⭐️⭐️
    Sep 14, 2020 12:39 PM UTC

    @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

    13 replies

    daniel.boon
    Helper ⭐️⭐️⭐️
    Jun 26, 2020 11:53 AM UTC

    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.

    Translate
    inSided product alumnus
    RonHAuthor
    Contributor ⭐️
    Jun 26, 2020 1:11 PM UTC

    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

     

    Translate
    mstone
    Helper ⭐️
    Jun 29, 2020 9:50 PM UTC

    @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. 

    Translate
    tom.shaddock
    Gainsight Employee ⭐️⭐️
    Jun 30, 2020 8:28 AM UTC

    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!

    Translate
    daniel.boon
    Helper ⭐️⭐️⭐️
    Jun 30, 2020 8:31 AM UTC

    @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 :)

    Translate
    inSided product alumnus
    tom.shaddock
    Gainsight Employee ⭐️⭐️
    Jul 20, 2020 8:25 AM UTC

    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!

    Translate
    daniel.boon
    Helper ⭐️⭐️⭐️
    Sep 14, 2020 12:39 PM UTC

    @RonH @mstone 

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

    Translate
    inSided product alumnus
    Contributor ⭐️
    Nov 20, 2020 11:45 AM UTC

    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?

    Translate
    daniel.boon
    Helper ⭐️⭐️⭐️
    Dec 2, 2020 9:04 AM UTC

    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

    Translate
    inSided product alumnus
    Helper ⭐️⭐️
    Jul 21, 2021 3:05 PM UTC

    @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. 

    Translate