The Roles API is used to create and manage Datadog roles, what
global permissions
they grant, and which users belong to them.
Permissions related to specific account assets can be granted to roles
in the Datadog application without using this API. For example, granting
read access on a specific log index to a role can be done in Datadog from the
Pipelines page.
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* List permissions returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.RolesApi(configuration);apiInstance.listPermissions().then((data: v2.PermissionsResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
Returns all roles, including their names and their unique identifiers.
This endpoint requires the user_access_read permission.
OAuth apps require the user_access_read authorization scope to access this endpoint.
Arguments
Query Strings
Name
Type
Description
page[size]
integer
Size for a given page. The maximum allowed value is 100.
page[number]
integer
Specific page number to return.
sort
enum
Sort roles depending on the given field. Sort order is ascending by default.
Sort order is descending if the field is prefixed by a negative sign, for example:
sort=-name. Allowed enum values: name, -name, modified_at, -modified_at, user_count, -user_count
"""
List roles returns "OK" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.roles_apiimportRolesApi# there is a valid "role" in the systemROLE_DATA_ATTRIBUTES_NAME=environ["ROLE_DATA_ATTRIBUTES_NAME"]configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=RolesApi(api_client)response=api_instance.list_roles(filter=ROLE_DATA_ATTRIBUTES_NAME,)print(response)
# List roles returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::RolesAPI.new# there is a valid "role" in the systemROLE_DATA_ATTRIBUTES_NAME=ENV["ROLE_DATA_ATTRIBUTES_NAME"]opts={filter:ROLE_DATA_ATTRIBUTES_NAME,}papi_instance.list_roles(opts)
// List roles returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){// there is a valid "role" in the system
RoleDataAttributesName:=os.Getenv("ROLE_DATA_ATTRIBUTES_NAME")ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewRolesApi(apiClient)resp,r,err:=api.ListRoles(ctx,*datadogV2.NewListRolesOptionalParameters().WithFilter(RoleDataAttributesName))iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `RolesApi.ListRoles`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `RolesApi.ListRoles`:\n%s\n",responseContent)}
// List roles returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.RolesApi;importcom.datadog.api.client.v2.api.RolesApi.ListRolesOptionalParameters;importcom.datadog.api.client.v2.model.RolesResponse;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();RolesApiapiInstance=newRolesApi(defaultClient);// there is a valid "role" in the systemStringROLE_DATA_ATTRIBUTES_NAME=System.getenv("ROLE_DATA_ATTRIBUTES_NAME");try{RolesResponseresult=apiInstance.listRoles(newListRolesOptionalParameters().filter(ROLE_DATA_ATTRIBUTES_NAME));System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling RolesApi#listRoles");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
// List roles returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_roles::ListRolesOptionalParams;usedatadog_api_client::datadogV2::api_roles::RolesAPI;#[tokio::main]asyncfnmain(){// there is a valid "role" in the system
letrole_data_attributes_name=std::env::var("ROLE_DATA_ATTRIBUTES_NAME").unwrap();letconfiguration=datadog::Configuration::new();letapi=RolesAPI::with_config(configuration);letresp=api.list_roles(ListRolesOptionalParams::default().filter(role_data_attributes_name.clone())).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* List roles returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.RolesApi(configuration);// there is a valid "role" in the system
constROLE_DATA_ATTRIBUTES_NAME=process.env.ROLE_DATA_ATTRIBUTES_NAMEasstring;constparams: v2.RolesApiListRolesRequest={filter: ROLE_DATA_ATTRIBUTES_NAME,};apiInstance.listRoles(params).then((data: v2.RolesResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
// Create role with a permission returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){// there is a valid "permission" in the system
PermissionID:=os.Getenv("PERMISSION_ID")body:=datadogV2.RoleCreateRequest{Data:datadogV2.RoleCreateData{Type:datadogV2.ROLESTYPE_ROLES.Ptr(),Attributes:datadogV2.RoleCreateAttributes{Name:"Example-Role",},Relationships:&datadogV2.RoleRelationships{Permissions:&datadogV2.RelationshipToPermissions{Data:[]datadogV2.RelationshipToPermissionData{{Id:datadog.PtrString(PermissionID),Type:datadogV2.PERMISSIONSTYPE_PERMISSIONS.Ptr(),},},},},},}ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewRolesApi(apiClient)resp,r,err:=api.CreateRole(ctx,body)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `RolesApi.CreateRole`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `RolesApi.CreateRole`:\n%s\n",responseContent)}
// Create role with a permission returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.RolesApi;importcom.datadog.api.client.v2.model.PermissionsType;importcom.datadog.api.client.v2.model.RelationshipToPermissionData;importcom.datadog.api.client.v2.model.RelationshipToPermissions;importcom.datadog.api.client.v2.model.RoleCreateAttributes;importcom.datadog.api.client.v2.model.RoleCreateData;importcom.datadog.api.client.v2.model.RoleCreateRequest;importcom.datadog.api.client.v2.model.RoleCreateResponse;importcom.datadog.api.client.v2.model.RoleRelationships;importcom.datadog.api.client.v2.model.RolesType;importjava.util.Collections;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();RolesApiapiInstance=newRolesApi(defaultClient);// there is a valid "permission" in the systemStringPERMISSION_ID=System.getenv("PERMISSION_ID");RoleCreateRequestbody=newRoleCreateRequest().data(newRoleCreateData().type(RolesType.ROLES).attributes(newRoleCreateAttributes().name("Example-Role")).relationships(newRoleRelationships().permissions(newRelationshipToPermissions().data(Collections.singletonList(newRelationshipToPermissionData().id(PERMISSION_ID).type(PermissionsType.PERMISSIONS))))));try{RoleCreateResponseresult=apiInstance.createRole(body);System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling RolesApi#createRole");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
"""
Create role with a permission returns "OK" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.roles_apiimportRolesApifromdatadog_api_client.v2.model.permissions_typeimportPermissionsTypefromdatadog_api_client.v2.model.relationship_to_permission_dataimportRelationshipToPermissionDatafromdatadog_api_client.v2.model.relationship_to_permissionsimportRelationshipToPermissionsfromdatadog_api_client.v2.model.role_create_attributesimportRoleCreateAttributesfromdatadog_api_client.v2.model.role_create_dataimportRoleCreateDatafromdatadog_api_client.v2.model.role_create_requestimportRoleCreateRequestfromdatadog_api_client.v2.model.role_relationshipsimportRoleRelationshipsfromdatadog_api_client.v2.model.roles_typeimportRolesType# there is a valid "permission" in the systemPERMISSION_ID=environ["PERMISSION_ID"]body=RoleCreateRequest(data=RoleCreateData(type=RolesType.ROLES,attributes=RoleCreateAttributes(name="Example-Role",),relationships=RoleRelationships(permissions=RelationshipToPermissions(data=[RelationshipToPermissionData(id=PERMISSION_ID,type=PermissionsType.PERMISSIONS,),],),),),)configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=RolesApi(api_client)response=api_instance.create_role(body=body)print(response)
# Create role with a permission returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::RolesAPI.new# there is a valid "permission" in the systemPERMISSION_ID=ENV["PERMISSION_ID"]body=DatadogAPIClient::V2::RoleCreateRequest.new({data:DatadogAPIClient::V2::RoleCreateData.new({type:DatadogAPIClient::V2::RolesType::ROLES,attributes:DatadogAPIClient::V2::RoleCreateAttributes.new({name:"Example-Role",}),relationships:DatadogAPIClient::V2::RoleRelationships.new({permissions:DatadogAPIClient::V2::RelationshipToPermissions.new({data:[DatadogAPIClient::V2::RelationshipToPermissionData.new({id:PERMISSION_ID,type:DatadogAPIClient::V2::PermissionsType::PERMISSIONS,}),],}),}),}),})papi_instance.create_role(body)
// Create role with a permission returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_roles::RolesAPI;usedatadog_api_client::datadogV2::model::PermissionsType;usedatadog_api_client::datadogV2::model::RelationshipToPermissionData;usedatadog_api_client::datadogV2::model::RelationshipToPermissions;usedatadog_api_client::datadogV2::model::RoleCreateAttributes;usedatadog_api_client::datadogV2::model::RoleCreateData;usedatadog_api_client::datadogV2::model::RoleCreateRequest;usedatadog_api_client::datadogV2::model::RoleRelationships;usedatadog_api_client::datadogV2::model::RolesType;#[tokio::main]asyncfnmain(){// there is a valid "permission" in the system
letpermission_id=std::env::var("PERMISSION_ID").unwrap();letbody=RoleCreateRequest::new(RoleCreateData::new(RoleCreateAttributes::new("Example-Role".to_string())).relationships(RoleRelationships::new().permissions(RelationshipToPermissions::new().data(vec![RelationshipToPermissionData::new().id(permission_id.clone()).type_(PermissionsType::PERMISSIONS)]),)).type_(RolesType::ROLES),);letconfiguration=datadog::Configuration::new();letapi=RolesAPI::with_config(configuration);letresp=api.create_role(body).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* Create role with a permission returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.RolesApi(configuration);// there is a valid "permission" in the system
constPERMISSION_ID=process.env.PERMISSION_IDasstring;constparams: v2.RolesApiCreateRoleRequest={body:{data:{type:"roles",attributes:{name:"Example-Role",},relationships:{permissions:{data:[{id: PERMISSION_ID,type:"permissions",},],},},},},};apiInstance.createRole(params).then((data: v2.RoleCreateResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
"""
Get a role returns "OK" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.roles_apiimportRolesApi# there is a valid "role" in the systemROLE_DATA_ID=environ["ROLE_DATA_ID"]configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=RolesApi(api_client)response=api_instance.get_role(role_id=ROLE_DATA_ID,)print(response)
# Get a role returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::RolesAPI.new# there is a valid "role" in the systemROLE_DATA_ID=ENV["ROLE_DATA_ID"]papi_instance.get_role(ROLE_DATA_ID)
// Get a role returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){// there is a valid "role" in the system
RoleDataID:=os.Getenv("ROLE_DATA_ID")ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewRolesApi(apiClient)resp,r,err:=api.GetRole(ctx,RoleDataID)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `RolesApi.GetRole`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `RolesApi.GetRole`:\n%s\n",responseContent)}
// Get a role returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.RolesApi;importcom.datadog.api.client.v2.model.RoleResponse;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();RolesApiapiInstance=newRolesApi(defaultClient);// there is a valid "role" in the systemStringROLE_DATA_ID=System.getenv("ROLE_DATA_ID");try{RoleResponseresult=apiInstance.getRole(ROLE_DATA_ID);System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling RolesApi#getRole");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
// Get a role returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_roles::RolesAPI;#[tokio::main]asyncfnmain(){// there is a valid "role" in the system
letrole_data_id=std::env::var("ROLE_DATA_ID").unwrap();letconfiguration=datadog::Configuration::new();letapi=RolesAPI::with_config(configuration);letresp=api.get_role(role_data_id.clone()).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* Get a role returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.RolesApi(configuration);// there is a valid "role" in the system
constROLE_DATA_ID=process.env.ROLE_DATA_IDasstring;constparams: v2.RolesApiGetRoleRequest={roleId: ROLE_DATA_ID,};apiInstance.getRole(params).then((data: v2.RoleResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
"""
Update a role returns "OK" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.roles_apiimportRolesApifromdatadog_api_client.v2.model.permissions_typeimportPermissionsTypefromdatadog_api_client.v2.model.relationship_to_permission_dataimportRelationshipToPermissionDatafromdatadog_api_client.v2.model.relationship_to_permissionsimportRelationshipToPermissionsfromdatadog_api_client.v2.model.role_relationshipsimportRoleRelationshipsfromdatadog_api_client.v2.model.role_update_attributesimportRoleUpdateAttributesfromdatadog_api_client.v2.model.role_update_dataimportRoleUpdateDatafromdatadog_api_client.v2.model.role_update_requestimportRoleUpdateRequestfromdatadog_api_client.v2.model.roles_typeimportRolesType# there is a valid "role" in the systemROLE_DATA_ATTRIBUTES_NAME=environ["ROLE_DATA_ATTRIBUTES_NAME"]ROLE_DATA_ID=environ["ROLE_DATA_ID"]# there is a valid "permission" in the systemPERMISSION_ID=environ["PERMISSION_ID"]body=RoleUpdateRequest(data=RoleUpdateData(id=ROLE_DATA_ID,type=RolesType.ROLES,attributes=RoleUpdateAttributes(name="developers-updated",),relationships=RoleRelationships(permissions=RelationshipToPermissions(data=[RelationshipToPermissionData(id=PERMISSION_ID,type=PermissionsType.PERMISSIONS,),],),),),)configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=RolesApi(api_client)response=api_instance.update_role(role_id=ROLE_DATA_ID,body=body)print(response)
# Update a role returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::RolesAPI.new# there is a valid "role" in the systemROLE_DATA_ATTRIBUTES_NAME=ENV["ROLE_DATA_ATTRIBUTES_NAME"]ROLE_DATA_ID=ENV["ROLE_DATA_ID"]# there is a valid "permission" in the systemPERMISSION_ID=ENV["PERMISSION_ID"]body=DatadogAPIClient::V2::RoleUpdateRequest.new({data:DatadogAPIClient::V2::RoleUpdateData.new({id:ROLE_DATA_ID,type:DatadogAPIClient::V2::RolesType::ROLES,attributes:DatadogAPIClient::V2::RoleUpdateAttributes.new({name:"developers-updated",}),relationships:DatadogAPIClient::V2::RoleRelationships.new({permissions:DatadogAPIClient::V2::RelationshipToPermissions.new({data:[DatadogAPIClient::V2::RelationshipToPermissionData.new({id:PERMISSION_ID,type:DatadogAPIClient::V2::PermissionsType::PERMISSIONS,}),],}),}),}),})papi_instance.update_role(ROLE_DATA_ID,body)
// Update a role returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){// there is a valid "role" in the system
RoleDataID:=os.Getenv("ROLE_DATA_ID")// there is a valid "permission" in the system
PermissionID:=os.Getenv("PERMISSION_ID")body:=datadogV2.RoleUpdateRequest{Data:datadogV2.RoleUpdateData{Id:RoleDataID,Type:datadogV2.ROLESTYPE_ROLES,Attributes:datadogV2.RoleUpdateAttributes{Name:datadog.PtrString("developers-updated"),},Relationships:&datadogV2.RoleRelationships{Permissions:&datadogV2.RelationshipToPermissions{Data:[]datadogV2.RelationshipToPermissionData{{Id:datadog.PtrString(PermissionID),Type:datadogV2.PERMISSIONSTYPE_PERMISSIONS.Ptr(),},},},},},}ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewRolesApi(apiClient)resp,r,err:=api.UpdateRole(ctx,RoleDataID,body)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `RolesApi.UpdateRole`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `RolesApi.UpdateRole`:\n%s\n",responseContent)}
// Update a role returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.RolesApi;importcom.datadog.api.client.v2.model.PermissionsType;importcom.datadog.api.client.v2.model.RelationshipToPermissionData;importcom.datadog.api.client.v2.model.RelationshipToPermissions;importcom.datadog.api.client.v2.model.RoleRelationships;importcom.datadog.api.client.v2.model.RoleUpdateAttributes;importcom.datadog.api.client.v2.model.RoleUpdateData;importcom.datadog.api.client.v2.model.RoleUpdateRequest;importcom.datadog.api.client.v2.model.RoleUpdateResponse;importcom.datadog.api.client.v2.model.RolesType;importjava.util.Collections;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();RolesApiapiInstance=newRolesApi(defaultClient);// there is a valid "role" in the systemStringROLE_DATA_ATTRIBUTES_NAME=System.getenv("ROLE_DATA_ATTRIBUTES_NAME");StringROLE_DATA_ID=System.getenv("ROLE_DATA_ID");// there is a valid "permission" in the systemStringPERMISSION_ID=System.getenv("PERMISSION_ID");RoleUpdateRequestbody=newRoleUpdateRequest().data(newRoleUpdateData().id(ROLE_DATA_ID).type(RolesType.ROLES).attributes(newRoleUpdateAttributes().name("developers-updated")).relationships(newRoleRelationships().permissions(newRelationshipToPermissions().data(Collections.singletonList(newRelationshipToPermissionData().id(PERMISSION_ID).type(PermissionsType.PERMISSIONS))))));try{RoleUpdateResponseresult=apiInstance.updateRole(ROLE_DATA_ID,body);System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling RolesApi#updateRole");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
// Update a role returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_roles::RolesAPI;usedatadog_api_client::datadogV2::model::PermissionsType;usedatadog_api_client::datadogV2::model::RelationshipToPermissionData;usedatadog_api_client::datadogV2::model::RelationshipToPermissions;usedatadog_api_client::datadogV2::model::RoleRelationships;usedatadog_api_client::datadogV2::model::RoleUpdateAttributes;usedatadog_api_client::datadogV2::model::RoleUpdateData;usedatadog_api_client::datadogV2::model::RoleUpdateRequest;usedatadog_api_client::datadogV2::model::RolesType;#[tokio::main]asyncfnmain(){// there is a valid "role" in the system
letrole_data_id=std::env::var("ROLE_DATA_ID").unwrap();// there is a valid "permission" in the system
letpermission_id=std::env::var("PERMISSION_ID").unwrap();letbody=RoleUpdateRequest::new(RoleUpdateData::new(RoleUpdateAttributes::new().name("developers-updated".to_string()),role_data_id.clone(),RolesType::ROLES,).relationships(RoleRelationships::new().permissions(RelationshipToPermissions::new().data(vec![RelationshipToPermissionData::new().id(permission_id.clone()).type_(PermissionsType::PERMISSIONS)]),)),);letconfiguration=datadog::Configuration::new();letapi=RolesAPI::with_config(configuration);letresp=api.update_role(role_data_id.clone(),body).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* Update a role returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.RolesApi(configuration);// there is a valid "role" in the system
constROLE_DATA_ID=process.env.ROLE_DATA_IDasstring;// there is a valid "permission" in the system
constPERMISSION_ID=process.env.PERMISSION_IDasstring;constparams: v2.RolesApiUpdateRoleRequest={body:{data:{id: ROLE_DATA_ID,type:"roles",attributes:{name:"developers-updated",},relationships:{permissions:{data:[{id: PERMISSION_ID,type:"permissions",},],},},},},roleId: ROLE_DATA_ID,};apiInstance.updateRole(params).then((data: v2.RoleUpdateResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
"""
Delete role returns "OK" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.roles_apiimportRolesApi# there is a valid "role" in the systemROLE_DATA_ID=environ["ROLE_DATA_ID"]configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=RolesApi(api_client)api_instance.delete_role(role_id=ROLE_DATA_ID,)
# Delete role returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::RolesAPI.new# there is a valid "role" in the systemROLE_DATA_ID=ENV["ROLE_DATA_ID"]api_instance.delete_role(ROLE_DATA_ID)
// Delete role returns "OK" response
packagemainimport("context""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){// there is a valid "role" in the system
RoleDataID:=os.Getenv("ROLE_DATA_ID")ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewRolesApi(apiClient)r,err:=api.DeleteRole(ctx,RoleDataID)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `RolesApi.DeleteRole`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}}
// Delete role returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.RolesApi;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();RolesApiapiInstance=newRolesApi(defaultClient);// there is a valid "role" in the systemStringROLE_DATA_ID=System.getenv("ROLE_DATA_ID");try{apiInstance.deleteRole(ROLE_DATA_ID);}catch(ApiExceptione){System.err.println("Exception when calling RolesApi#deleteRole");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
// Delete role returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_roles::RolesAPI;#[tokio::main]asyncfnmain(){// there is a valid "role" in the system
letrole_data_id=std::env::var("ROLE_DATA_ID").unwrap();letconfiguration=datadog::Configuration::new();letapi=RolesAPI::with_config(configuration);letresp=api.delete_role(role_data_id.clone()).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* Delete role returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.RolesApi(configuration);// there is a valid "role" in the system
constROLE_DATA_ID=process.env.ROLE_DATA_IDasstring;constparams: v2.RolesApiDeleteRoleRequest={roleId: ROLE_DATA_ID,};apiInstance.deleteRole(params).then((data: any)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
"""
List permissions for a role returns "OK" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.roles_apiimportRolesApi# there is a valid "role" in the systemROLE_DATA_ID=environ["ROLE_DATA_ID"]configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=RolesApi(api_client)response=api_instance.list_role_permissions(role_id=ROLE_DATA_ID,)print(response)
# List permissions for a role returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::RolesAPI.new# there is a valid "role" in the systemROLE_DATA_ID=ENV["ROLE_DATA_ID"]papi_instance.list_role_permissions(ROLE_DATA_ID)
// List permissions for a role returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){// there is a valid "role" in the system
RoleDataID:=os.Getenv("ROLE_DATA_ID")ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewRolesApi(apiClient)resp,r,err:=api.ListRolePermissions(ctx,RoleDataID)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `RolesApi.ListRolePermissions`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `RolesApi.ListRolePermissions`:\n%s\n",responseContent)}
// List permissions for a role returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.RolesApi;importcom.datadog.api.client.v2.model.PermissionsResponse;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();RolesApiapiInstance=newRolesApi(defaultClient);// there is a valid "role" in the systemStringROLE_DATA_ID=System.getenv("ROLE_DATA_ID");try{PermissionsResponseresult=apiInstance.listRolePermissions(ROLE_DATA_ID);System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling RolesApi#listRolePermissions");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
// List permissions for a role returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_roles::RolesAPI;#[tokio::main]asyncfnmain(){// there is a valid "role" in the system
letrole_data_id=std::env::var("ROLE_DATA_ID").unwrap();letconfiguration=datadog::Configuration::new();letapi=RolesAPI::with_config(configuration);letresp=api.list_role_permissions(role_data_id.clone()).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* List permissions for a role returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.RolesApi(configuration);// there is a valid "role" in the system
constROLE_DATA_ID=process.env.ROLE_DATA_IDasstring;constparams: v2.RolesApiListRolePermissionsRequest={roleId: ROLE_DATA_ID,};apiInstance.listRolePermissions(params).then((data: v2.PermissionsResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
// Grant permission to a role returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){// there is a valid "role" in the system
RoleDataID:=os.Getenv("ROLE_DATA_ID")// there is a valid "permission" in the system
PermissionID:=os.Getenv("PERMISSION_ID")body:=datadogV2.RelationshipToPermission{Data:&datadogV2.RelationshipToPermissionData{Id:datadog.PtrString(PermissionID),Type:datadogV2.PERMISSIONSTYPE_PERMISSIONS.Ptr(),},}ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewRolesApi(apiClient)resp,r,err:=api.AddPermissionToRole(ctx,RoleDataID,body)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `RolesApi.AddPermissionToRole`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `RolesApi.AddPermissionToRole`:\n%s\n",responseContent)}
// Grant permission to a role returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.RolesApi;importcom.datadog.api.client.v2.model.PermissionsResponse;importcom.datadog.api.client.v2.model.PermissionsType;importcom.datadog.api.client.v2.model.RelationshipToPermission;importcom.datadog.api.client.v2.model.RelationshipToPermissionData;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();RolesApiapiInstance=newRolesApi(defaultClient);// there is a valid "role" in the systemStringROLE_DATA_ID=System.getenv("ROLE_DATA_ID");// there is a valid "permission" in the systemStringPERMISSION_ID=System.getenv("PERMISSION_ID");RelationshipToPermissionbody=newRelationshipToPermission().data(newRelationshipToPermissionData().id(PERMISSION_ID).type(PermissionsType.PERMISSIONS));try{PermissionsResponseresult=apiInstance.addPermissionToRole(ROLE_DATA_ID,body);System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling RolesApi#addPermissionToRole");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
"""
Grant permission to a role returns "OK" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.roles_apiimportRolesApifromdatadog_api_client.v2.model.permissions_typeimportPermissionsTypefromdatadog_api_client.v2.model.relationship_to_permissionimportRelationshipToPermissionfromdatadog_api_client.v2.model.relationship_to_permission_dataimportRelationshipToPermissionData# there is a valid "role" in the systemROLE_DATA_ID=environ["ROLE_DATA_ID"]# there is a valid "permission" in the systemPERMISSION_ID=environ["PERMISSION_ID"]body=RelationshipToPermission(data=RelationshipToPermissionData(id=PERMISSION_ID,type=PermissionsType.PERMISSIONS,),)configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=RolesApi(api_client)response=api_instance.add_permission_to_role(role_id=ROLE_DATA_ID,body=body)print(response)
# Grant permission to a role returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::RolesAPI.new# there is a valid "role" in the systemROLE_DATA_ID=ENV["ROLE_DATA_ID"]# there is a valid "permission" in the systemPERMISSION_ID=ENV["PERMISSION_ID"]body=DatadogAPIClient::V2::RelationshipToPermission.new({data:DatadogAPIClient::V2::RelationshipToPermissionData.new({id:PERMISSION_ID,type:DatadogAPIClient::V2::PermissionsType::PERMISSIONS,}),})papi_instance.add_permission_to_role(ROLE_DATA_ID,body)
// Grant permission to a role returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_roles::RolesAPI;usedatadog_api_client::datadogV2::model::PermissionsType;usedatadog_api_client::datadogV2::model::RelationshipToPermission;usedatadog_api_client::datadogV2::model::RelationshipToPermissionData;#[tokio::main]asyncfnmain(){// there is a valid "role" in the system
letrole_data_id=std::env::var("ROLE_DATA_ID").unwrap();// there is a valid "permission" in the system
letpermission_id=std::env::var("PERMISSION_ID").unwrap();letbody=RelationshipToPermission::new().data(RelationshipToPermissionData::new().id(permission_id.clone()).type_(PermissionsType::PERMISSIONS),);letconfiguration=datadog::Configuration::new();letapi=RolesAPI::with_config(configuration);letresp=api.add_permission_to_role(role_data_id.clone(),body).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* Grant permission to a role returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.RolesApi(configuration);// there is a valid "role" in the system
constROLE_DATA_ID=process.env.ROLE_DATA_IDasstring;// there is a valid "permission" in the system
constPERMISSION_ID=process.env.PERMISSION_IDasstring;constparams: v2.RolesApiAddPermissionToRoleRequest={body:{data:{id: PERMISSION_ID,type:"permissions",},},roleId: ROLE_DATA_ID,};apiInstance.addPermissionToRole(params).then((data: v2.PermissionsResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
// Revoke permission returns "OK" response
packagemainimport("context""encoding/json""fmt""os""github.com/DataDog/datadog-api-client-go/v2/api/datadog""github.com/DataDog/datadog-api-client-go/v2/api/datadogV2")funcmain(){// there is a valid "role" in the system
RoleDataID:=os.Getenv("ROLE_DATA_ID")// there is a valid "permission" in the system
PermissionID:=os.Getenv("PERMISSION_ID")body:=datadogV2.RelationshipToPermission{Data:&datadogV2.RelationshipToPermissionData{Id:datadog.PtrString(PermissionID),Type:datadogV2.PERMISSIONSTYPE_PERMISSIONS.Ptr(),},}ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewRolesApi(apiClient)resp,r,err:=api.RemovePermissionFromRole(ctx,RoleDataID,body)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `RolesApi.RemovePermissionFromRole`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `RolesApi.RemovePermissionFromRole`:\n%s\n",responseContent)}
// Revoke permission returns "OK" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.RolesApi;importcom.datadog.api.client.v2.model.PermissionsResponse;importcom.datadog.api.client.v2.model.PermissionsType;importcom.datadog.api.client.v2.model.RelationshipToPermission;importcom.datadog.api.client.v2.model.RelationshipToPermissionData;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();RolesApiapiInstance=newRolesApi(defaultClient);// there is a valid "role" in the systemStringROLE_DATA_ID=System.getenv("ROLE_DATA_ID");// there is a valid "permission" in the systemStringPERMISSION_ID=System.getenv("PERMISSION_ID");RelationshipToPermissionbody=newRelationshipToPermission().data(newRelationshipToPermissionData().id(PERMISSION_ID).type(PermissionsType.PERMISSIONS));try{PermissionsResponseresult=apiInstance.removePermissionFromRole(ROLE_DATA_ID,body);System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling RolesApi#removePermissionFromRole");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
"""
Revoke permission returns "OK" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.roles_apiimportRolesApifromdatadog_api_client.v2.model.permissions_typeimportPermissionsTypefromdatadog_api_client.v2.model.relationship_to_permissionimportRelationshipToPermissionfromdatadog_api_client.v2.model.relationship_to_permission_dataimportRelationshipToPermissionData# there is a valid "role" in the systemROLE_DATA_ID=environ["ROLE_DATA_ID"]# there is a valid "permission" in the systemPERMISSION_ID=environ["PERMISSION_ID"]body=RelationshipToPermission(data=RelationshipToPermissionData(id=PERMISSION_ID,type=PermissionsType.PERMISSIONS,),)configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=RolesApi(api_client)response=api_instance.remove_permission_from_role(role_id=ROLE_DATA_ID,body=body)print(response)
# Revoke permission returns "OK" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::RolesAPI.new# there is a valid "role" in the systemROLE_DATA_ID=ENV["ROLE_DATA_ID"]# there is a valid "permission" in the systemPERMISSION_ID=ENV["PERMISSION_ID"]body=DatadogAPIClient::V2::RelationshipToPermission.new({data:DatadogAPIClient::V2::RelationshipToPermissionData.new({id:PERMISSION_ID,type:DatadogAPIClient::V2::PermissionsType::PERMISSIONS,}),})papi_instance.remove_permission_from_role(ROLE_DATA_ID,body)
// Revoke permission returns "OK" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_roles::RolesAPI;usedatadog_api_client::datadogV2::model::PermissionsType;usedatadog_api_client::datadogV2::model::RelationshipToPermission;usedatadog_api_client::datadogV2::model::RelationshipToPermissionData;#[tokio::main]asyncfnmain(){// there is a valid "role" in the system
letrole_data_id=std::env::var("ROLE_DATA_ID").unwrap();// there is a valid "permission" in the system
letpermission_id=std::env::var("PERMISSION_ID").unwrap();letbody=RelationshipToPermission::new().data(RelationshipToPermissionData::new().id(permission_id.clone()).type_(PermissionsType::PERMISSIONS),);letconfiguration=datadog::Configuration::new();letapi=RolesAPI::with_config(configuration);letresp=api.remove_permission_from_role(role_data_id.clone(),body).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* Revoke permission returns "OK" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.RolesApi(configuration);// there is a valid "role" in the system
constROLE_DATA_ID=process.env.ROLE_DATA_IDasstring;// there is a valid "permission" in the system
constPERMISSION_ID=process.env.PERMISSION_IDasstring;constparams: v2.RolesApiRemovePermissionFromRoleRequest={body:{data:{id: PERMISSION_ID,type:"permissions",},},roleId: ROLE_DATA_ID,};apiInstance.removePermissionFromRole(params).then((data: v2.PermissionsResponse)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
OAuth apps require the user_access_read authorization scope to access this endpoint.
Arguments
Path Parameters
Name
Type
Description
role_id [required]
string
The unique identifier of the role.
Query Strings
Name
Type
Description
page[size]
integer
Size for a given page. The maximum allowed value is 100.
page[number]
integer
Specific page number to return.
sort
string
User attribute to order results by. Sort order is ascending by default.
Sort order is descending if the field is prefixed by a negative sign,
for example sort=-name. Options: name, email, status.
filter
string
Filter all users by the given string. Defaults to no filtering.