Create a new notification rule for a user. The authenticated user must be the target user or have the on_call_admin permission
This endpoint requires the on_call_respond permission.
## default
#
# Path parameters exportuser_id="00000000-0000-0000-0000-000000000000" # Use a Personal Access Token or Service Access Token exportDD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"
// Create an On-Call notification rule for a user returns "Created" responsepackagemainimport("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 "user" in the systemUserDataID:=os.Getenv("USER_DATA_ID")// there is a valid "oncall_email_notification_channel" in the systemOncallEmailNotificationChannelDataID:=os.Getenv("ONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID")body:=datadogV2.CreateOnCallNotificationRuleRequest{Data:datadogV2.CreateOnCallNotificationRuleRequestData{Attributes:&datadogV2.OnCallNotificationRuleRequestAttributes{Category:datadogV2.ONCALLNOTIFICATIONRULECATEGORY_HIGH_URGENCY.Ptr(),DelayMinutes:datadog.PtrInt64(0),},Relationships:&datadogV2.OnCallNotificationRuleRelationships{Channel:&datadogV2.OnCallNotificationRuleChannelRelationship{Data:datadogV2.OnCallNotificationRuleChannelRelationshipData{Id:datadog.PtrString(OncallEmailNotificationChannelDataID),Type:datadogV2.NOTIFICATIONCHANNELTYPE_NOTIFICATION_CHANNELS.Ptr(),},},},Type:datadogV2.ONCALLNOTIFICATIONRULETYPE_NOTIFICATION_RULES,},}ctx:=datadog.NewDefaultContext(context.Background())ctx=context.WithValue(ctx,datadog.ContextAccessToken,os.Getenv("DD_BEARER_TOKEN"))configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewOnCallApi(apiClient)resp,r,err:=api.CreateUserNotificationRule(ctx,UserDataID,body)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `OnCallApi.CreateUserNotificationRule`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `OnCallApi.CreateUserNotificationRule`:\n%s\n",responseContent)}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"go run"main.go"
// Create an On-Call notification rule for a user returns "Created" responseimportcom.datadog.api.client.ApiClient;importcom.datadog.api.client.ApiException;importcom.datadog.api.client.v2.api.OnCallApi;importcom.datadog.api.client.v2.model.CreateOnCallNotificationRuleRequest;importcom.datadog.api.client.v2.model.CreateOnCallNotificationRuleRequestData;importcom.datadog.api.client.v2.model.NotificationChannelType;importcom.datadog.api.client.v2.model.OnCallNotificationRule;importcom.datadog.api.client.v2.model.OnCallNotificationRuleCategory;importcom.datadog.api.client.v2.model.OnCallNotificationRuleChannelRelationship;importcom.datadog.api.client.v2.model.OnCallNotificationRuleChannelRelationshipData;importcom.datadog.api.client.v2.model.OnCallNotificationRuleRelationships;importcom.datadog.api.client.v2.model.OnCallNotificationRuleRequestAttributes;importcom.datadog.api.client.v2.model.OnCallNotificationRuleType;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();defaultClient.setAccessToken(System.getenv("DD_BEARER_TOKEN"));OnCallApiapiInstance=newOnCallApi(defaultClient);// there is a valid "user" in the systemStringUSER_DATA_ID=System.getenv("USER_DATA_ID");// there is a valid "oncall_email_notification_channel" in the systemStringONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID=System.getenv("ONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID");CreateOnCallNotificationRuleRequestbody=newCreateOnCallNotificationRuleRequest().data(newCreateOnCallNotificationRuleRequestData().attributes(newOnCallNotificationRuleRequestAttributes().category(OnCallNotificationRuleCategory.HIGH_URGENCY).delayMinutes(0L)).relationships(newOnCallNotificationRuleRelationships().channel(newOnCallNotificationRuleChannelRelationship().data(newOnCallNotificationRuleChannelRelationshipData().id(ONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID).type(NotificationChannelType.NOTIFICATION_CHANNELS)))).type(OnCallNotificationRuleType.NOTIFICATION_RULES));try{OnCallNotificationRuleresult=apiInstance.createUserNotificationRule(USER_DATA_ID,body);System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling OnCallApi#createUserNotificationRule");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"java"Example.java"
"""
Create an On-Call notification rule for a user returns "Created" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.on_call_apiimportOnCallApifromdatadog_api_client.v2.model.create_on_call_notification_rule_requestimportCreateOnCallNotificationRuleRequestfromdatadog_api_client.v2.model.create_on_call_notification_rule_request_dataimport(CreateOnCallNotificationRuleRequestData,)fromdatadog_api_client.v2.model.notification_channel_typeimportNotificationChannelTypefromdatadog_api_client.v2.model.on_call_notification_rule_categoryimportOnCallNotificationRuleCategoryfromdatadog_api_client.v2.model.on_call_notification_rule_channel_relationshipimport(OnCallNotificationRuleChannelRelationship,)fromdatadog_api_client.v2.model.on_call_notification_rule_channel_relationship_dataimport(OnCallNotificationRuleChannelRelationshipData,)fromdatadog_api_client.v2.model.on_call_notification_rule_relationshipsimportOnCallNotificationRuleRelationshipsfromdatadog_api_client.v2.model.on_call_notification_rule_request_attributesimport(OnCallNotificationRuleRequestAttributes,)fromdatadog_api_client.v2.model.on_call_notification_rule_typeimportOnCallNotificationRuleType# there is a valid "user" in the systemUSER_DATA_ID=environ["USER_DATA_ID"]# there is a valid "oncall_email_notification_channel" in the systemONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID=environ["ONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID"]body=CreateOnCallNotificationRuleRequest(data=CreateOnCallNotificationRuleRequestData(attributes=OnCallNotificationRuleRequestAttributes(category=OnCallNotificationRuleCategory.HIGH_URGENCY,delay_minutes=0,),relationships=OnCallNotificationRuleRelationships(channel=OnCallNotificationRuleChannelRelationship(data=OnCallNotificationRuleChannelRelationshipData(id=ONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID,type=NotificationChannelType.NOTIFICATION_CHANNELS,),),),type=OnCallNotificationRuleType.NOTIFICATION_RULES,),)configuration=Configuration()configuration.access_token=environ["DD_BEARER_TOKEN"]withApiClient(configuration)asapi_client:api_instance=OnCallApi(api_client)response=api_instance.create_user_notification_rule(user_id=USER_DATA_ID,body=body)print(response)
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"python3"example.py"
# Create an On-Call notification rule for a user returns "Created" responserequire"datadog_api_client"DatadogAPIClient.configuredo|config|config.access_token=ENV["DD_BEARER_TOKEN"]endapi_instance=DatadogAPIClient::V2::OnCallAPI.new# there is a valid "user" in the systemUSER_DATA_ID=ENV["USER_DATA_ID"]# there is a valid "oncall_email_notification_channel" in the systemONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID=ENV["ONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID"]body=DatadogAPIClient::V2::CreateOnCallNotificationRuleRequest.new({data:DatadogAPIClient::V2::CreateOnCallNotificationRuleRequestData.new({attributes:DatadogAPIClient::V2::OnCallNotificationRuleRequestAttributes.new({category:DatadogAPIClient::V2::OnCallNotificationRuleCategory::HIGH_URGENCY,delay_minutes:0,}),relationships:DatadogAPIClient::V2::OnCallNotificationRuleRelationships.new({channel:DatadogAPIClient::V2::OnCallNotificationRuleChannelRelationship.new({data:DatadogAPIClient::V2::OnCallNotificationRuleChannelRelationshipData.new({id:ONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID,type:DatadogAPIClient::V2::NotificationChannelType::NOTIFICATION_CHANNELS,}),}),}),type:DatadogAPIClient::V2::OnCallNotificationRuleType::NOTIFICATION_RULES,}),})papi_instance.create_user_notification_rule(USER_DATA_ID,body)
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"rb"example.rb"
// Create an On-Call notification rule for a user returns "Created" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_on_call::OnCallAPI;usedatadog_api_client::datadogV2::model::CreateOnCallNotificationRuleRequest;usedatadog_api_client::datadogV2::model::CreateOnCallNotificationRuleRequestData;usedatadog_api_client::datadogV2::model::NotificationChannelType;usedatadog_api_client::datadogV2::model::OnCallNotificationRuleCategory;usedatadog_api_client::datadogV2::model::OnCallNotificationRuleChannelRelationship;usedatadog_api_client::datadogV2::model::OnCallNotificationRuleChannelRelationshipData;usedatadog_api_client::datadogV2::model::OnCallNotificationRuleRelationships;usedatadog_api_client::datadogV2::model::OnCallNotificationRuleRequestAttributes;usedatadog_api_client::datadogV2::model::OnCallNotificationRuleType;#[tokio::main]asyncfnmain(){// there is a valid "user" in the system
letuser_data_id=std::env::var("USER_DATA_ID").unwrap();// there is a valid "oncall_email_notification_channel" in the system
letoncall_email_notification_channel_data_id=std::env::var("ONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID").unwrap();letbody=CreateOnCallNotificationRuleRequest::new(CreateOnCallNotificationRuleRequestData::new(OnCallNotificationRuleType::NOTIFICATION_RULES,).attributes(OnCallNotificationRuleRequestAttributes::new().category(OnCallNotificationRuleCategory::HIGH_URGENCY).delay_minutes(0),).relationships(OnCallNotificationRuleRelationships::new().channel(OnCallNotificationRuleChannelRelationship::new(OnCallNotificationRuleChannelRelationshipData::new().id(oncall_email_notification_channel_data_id.clone()).type_(NotificationChannelType::NOTIFICATION_CHANNELS),),),),);letconfiguration=datadog::Configuration::new();letapi=OnCallAPI::with_config(configuration);letresp=api.create_user_notification_rule(user_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.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_API_KEY="<DD_API_KEY>"DD_APP_KEY="<DD_APP_KEY>"cargo run
/**
* Create an On-Call notification rule for a user returns "Created" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration({authMethods:{AuthZ:{accessToken: process.env.DD_BEARER_TOKENasstring,},},});constapiInstance=newv2.OnCallApi(configuration);// there is a valid "user" in the system
constUSER_DATA_ID=process.env.USER_DATA_IDasstring;// there is a valid "oncall_email_notification_channel" in the system
constONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID=process.env.ONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_IDasstring;constparams: v2.OnCallApiCreateUserNotificationRuleRequest={body:{data:{attributes:{category:"high_urgency",delayMinutes: 0,},relationships:{channel:{data:{id: ONCALL_EMAIL_NOTIFICATION_CHANNEL_DATA_ID,type:"notification_channels",},},},type:"notification_rules",},},userId: USER_DATA_ID,};apiInstance.createUserNotificationRule(params).then((data: v2.OnCallNotificationRule)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comuk1.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_BEARER_TOKEN="<PERSONAL_ACCESS_TOKEN OR SERVICE_ACCESS_TOKEN>"tsc"example.ts"
パーソナライズされたデモをリクエスト
Datadog を始める
Ask AI
AI-generated responses may be inaccurate. Verify important info.