Question

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

  • 24 June 2020
  • 7 replies
  • 239 views

  • Getting inSpired
  • 1 reply

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

 

 


7 replies

Userlevel 7
Badge +1

@RonH @mstone 

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

Userlevel 5
Badge +1

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!

Userlevel 7
Badge +1

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

Userlevel 5
Badge +1

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!

Userlevel 3
Badge

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

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

 

Userlevel 7
Badge +1

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.

Reply