Update User Roles
PUT https://api.coactive.ai/api/v1/auth-management/users/{user_id}/rolesContent-Type: application/jsonReplace a user’s roles.
This endpoint allows administrators to replace the roles assigned to a user.
The roles can be scoped to a specific context (e.g., dataset or system). If a context is provided, the roles will only be replaced within that context. If no context is provided, all roles (system-level and dataset-level) will be replaced.
To replace roles at the system level, use the “system” context. To replace roles at the dataset level, use the “dataset:{dataset_id}” context.
Authentication
Section titled “Authentication”Authorizationheader (bearer token, required) — Bearer authentication of the formBearer <token>, where token is your auth token.
Request
Section titled “Request”Path parameters
Section titled “Path parameters”user_id(string, required) — The ID of the user to update
Body (application/json)
Section titled “Body (application/json)”This endpoint expects an object.
roles(list of object, required) — New list of roles to assign to the userrole_id(string, required) — Name of the role (e.g., ‘admin’, ‘editor’, ‘viewer’)resource(string, optional, nullable) — Optional resource type the role applies to (e.g., ‘dataset’)resource_instance(string, optional, nullable) — Optional resource instance ID the role applies to
roles_context(string, optional, nullable) — Context for the roles to update. This can either be ‘system’ for system-level roles or ‘dataset:{dataset_id}’ for dataset-level roles.
Response
Section titled “Response”The updated user profile with new roles
user_id(string, required) — Unique identifier for the username(string, required) — Display name of the usercreated_at(string, required) — Timestamp when the user was createdroles(list of object, required) — List of roles assigned to the userrole_id(string, required) — Name of the role (e.g., ‘admin’, ‘editor’, ‘viewer’)resource(string, optional, nullable) — Optional resource type the role applies to (e.g., ‘dataset’)resource_instance(string, optional, nullable) — Optional resource instance ID the role applies to
email(string, optional, nullable) — Email address of the userpicture(string, optional, nullable) — URL to the user’s profile picturelast_login(string, optional, nullable) — Timestamp of the user’s last login
Errors
Section titled “Errors”422 Unprocessable Entity Error
Section titled “422 Unprocessable Entity Error”Validation Error
detail(list of object, optional)loc(list of string or integer, required)msg(string, required)type(string, required)
Examples
Section titled “Examples”Request
{ "roles": [ { "role_id": "admin" } ], "roles_context": "system"}Response
{ "user_id": "auth0|123", "name": "John Doe", "created_at": "2024-01-01T00:00:00Z", "roles": [ { "role_id": "admin" } ], "email": "john@example.com", "picture": "https://example.com/avatar.jpg", "last_login": "2024-01-02T00:00:00Z"}SDK Code
import requests
url = "https://api.coactive.ai/api/v1/auth-management/users/user_id/roles"
payload = { "roles": [{ "role_id": "admin" }], "roles_context": "system"}headers = { "Authorization": "Bearer <token>", "Content-Type": "application/json"}
response = requests.put(url, json=payload, headers=headers)
print(response.json())const url = 'https://api.coactive.ai/api/v1/auth-management/users/user_id/roles';const options = { method: 'PUT', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"roles":[{"role_id":"admin"}],"roles_context":"system"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}package main
import ( "fmt" "strings" "net/http" "io")
func main() {
url := "https://api.coactive.ai/api/v1/auth-management/users/user_id/roles"
payload := strings.NewReader("{\n \"roles\": [\n {\n \"role_id\": \"admin\"\n }\n ],\n \"roles_context\": \"system\"\n}")
req, _ := http.NewRequest("PUT", url, payload)
req.Header.Add("Authorization", "Bearer <token>") req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close() body, _ := io.ReadAll(res.Body)
fmt.Println(res) fmt.Println(string(body))
}require 'uri'require 'net/http'
url = URI("https://api.coactive.ai/api/v1/auth-management/users/user_id/roles")
http = Net::HTTP.new(url.host, url.port)http.use_ssl = true
request = Net::HTTP::Put.new(url)request["Authorization"] = 'Bearer <token>'request["Content-Type"] = 'application/json'request.body = "{\n \"roles\": [\n {\n \"role_id\": \"admin\"\n }\n ],\n \"roles_context\": \"system\"\n}"
response = http.request(request)puts response.read_bodyimport com.mashape.unirest.http.HttpResponse;import com.mashape.unirest.http.Unirest;
HttpResponse<String> response = Unirest.put("https://api.coactive.ai/api/v1/auth-management/users/user_id/roles") .header("Authorization", "Bearer <token>") .header("Content-Type", "application/json") .body("{\n \"roles\": [\n {\n \"role_id\": \"admin\"\n }\n ],\n \"roles_context\": \"system\"\n}") .asString();<?phprequire_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->request('PUT', 'https://api.coactive.ai/api/v1/auth-management/users/user_id/roles', [ 'body' => '{ "roles": [ { "role_id": "admin" } ], "roles_context": "system"}', 'headers' => [ 'Authorization' => 'Bearer <token>', 'Content-Type' => 'application/json', ],]);
echo $response->getBody();using RestSharp;
var client = new RestClient("https://api.coactive.ai/api/v1/auth-management/users/user_id/roles");var request = new RestRequest(Method.PUT);request.AddHeader("Authorization", "Bearer <token>");request.AddHeader("Content-Type", "application/json");request.AddParameter("application/json", "{\n \"roles\": [\n {\n \"role_id\": \"admin\"\n }\n ],\n \"roles_context\": \"system\"\n}", ParameterType.RequestBody);IRestResponse response = client.Execute(request);import Foundation
let headers = [ "Authorization": "Bearer <token>", "Content-Type": "application/json"]let parameters = [ "roles": [["role_id": "admin"]], "roles_context": "system"] as [String : Any]
let postData = JSONSerialization.data(withJSONObject: parameters, options: [])
let request = NSMutableURLRequest(url: NSURL(string: "https://api.coactive.ai/api/v1/auth-management/users/user_id/roles")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0)request.httpMethod = "PUT"request.allHTTPHeaderFields = headersrequest.httpBody = postData as Data
let session = URLSession.sharedlet dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) }})
dataTask.resume()