Create a new notification channel 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.
// Create an On-Call notification channel 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")body:=datadogV2.CreateUserNotificationChannelRequest{Data:datadogV2.CreateNotificationChannelData{Attributes:&datadogV2.CreateNotificationChannelAttributes{Config:&datadogV2.CreateNotificationChannelConfig{CreateEmailNotificationChannelConfig:&datadogV2.CreateEmailNotificationChannelConfig{Address:"foo@bar.com",Formats:[]datadogV2.NotificationChannelEmailFormatType{datadogV2.NOTIFICATIONCHANNELEMAILFORMATTYPE_HTML,},Type:datadogV2.NOTIFICATIONCHANNELEMAILCONFIGTYPE_EMAIL,}},},Type:datadogV2.NOTIFICATIONCHANNELTYPE_NOTIFICATION_CHANNELS,},}ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV2.NewOnCallApi(apiClient)resp,r,err:=api.CreateUserNotificationChannel(ctx,UserDataID,body)iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `OnCallApi.CreateUserNotificationChannel`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `OnCallApi.CreateUserNotificationChannel`:\n%s\n",responseContent)}
// Create an On-Call notification channel 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.CreateEmailNotificationChannelConfig;importcom.datadog.api.client.v2.model.CreateNotificationChannelAttributes;importcom.datadog.api.client.v2.model.CreateNotificationChannelConfig;importcom.datadog.api.client.v2.model.CreateNotificationChannelData;importcom.datadog.api.client.v2.model.CreateUserNotificationChannelRequest;importcom.datadog.api.client.v2.model.NotificationChannel;importcom.datadog.api.client.v2.model.NotificationChannelEmailConfigType;importcom.datadog.api.client.v2.model.NotificationChannelEmailFormatType;importcom.datadog.api.client.v2.model.NotificationChannelType;importjava.util.Collections;publicclassExample{publicstaticvoidmain(String[]args){ApiClientdefaultClient=ApiClient.getDefaultApiClient();OnCallApiapiInstance=newOnCallApi(defaultClient);// there is a valid "user" in the systemStringUSER_DATA_ID=System.getenv("USER_DATA_ID");CreateUserNotificationChannelRequestbody=newCreateUserNotificationChannelRequest().data(newCreateNotificationChannelData().attributes(newCreateNotificationChannelAttributes().config(newCreateNotificationChannelConfig(newCreateEmailNotificationChannelConfig().address("foo@bar.com").formats(Collections.singletonList(NotificationChannelEmailFormatType.HTML)).type(NotificationChannelEmailConfigType.EMAIL)))).type(NotificationChannelType.NOTIFICATION_CHANNELS));try{NotificationChannelresult=apiInstance.createUserNotificationChannel(USER_DATA_ID,body);System.out.println(result);}catch(ApiExceptione){System.err.println("Exception when calling OnCallApi#createUserNotificationChannel");System.err.println("Status code: "+e.getCode());System.err.println("Reason: "+e.getResponseBody());System.err.println("Response headers: "+e.getResponseHeaders());e.printStackTrace();}}}
"""
Create an On-Call notification channel for a user returns "Created" response
"""fromosimportenvironfromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v2.api.on_call_apiimportOnCallApifromdatadog_api_client.v2.model.create_email_notification_channel_configimportCreateEmailNotificationChannelConfigfromdatadog_api_client.v2.model.create_notification_channel_attributesimportCreateNotificationChannelAttributesfromdatadog_api_client.v2.model.create_notification_channel_dataimportCreateNotificationChannelDatafromdatadog_api_client.v2.model.create_user_notification_channel_requestimportCreateUserNotificationChannelRequestfromdatadog_api_client.v2.model.notification_channel_email_config_typeimportNotificationChannelEmailConfigTypefromdatadog_api_client.v2.model.notification_channel_email_format_typeimportNotificationChannelEmailFormatTypefromdatadog_api_client.v2.model.notification_channel_typeimportNotificationChannelType# there is a valid "user" in the systemUSER_DATA_ID=environ["USER_DATA_ID"]body=CreateUserNotificationChannelRequest(data=CreateNotificationChannelData(attributes=CreateNotificationChannelAttributes(config=CreateEmailNotificationChannelConfig(address="foo@bar.com",formats=[NotificationChannelEmailFormatType.HTML,],type=NotificationChannelEmailConfigType.EMAIL,),),type=NotificationChannelType.NOTIFICATION_CHANNELS,),)configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=OnCallApi(api_client)response=api_instance.create_user_notification_channel(user_id=USER_DATA_ID,body=body)print(response)
# Create an On-Call notification channel for a user returns "Created" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V2::OnCallAPI.new# there is a valid "user" in the systemUSER_DATA_ID=ENV["USER_DATA_ID"]body=DatadogAPIClient::V2::CreateUserNotificationChannelRequest.new({data:DatadogAPIClient::V2::CreateNotificationChannelData.new({attributes:DatadogAPIClient::V2::CreateNotificationChannelAttributes.new({config:DatadogAPIClient::V2::CreateEmailNotificationChannelConfig.new({address:"foo@bar.com",formats:[DatadogAPIClient::V2::NotificationChannelEmailFormatType::HTML,],type:DatadogAPIClient::V2::NotificationChannelEmailConfigType::EMAIL,}),}),type:DatadogAPIClient::V2::NotificationChannelType::NOTIFICATION_CHANNELS,}),})papi_instance.create_user_notification_channel(USER_DATA_ID,body)
// Create an On-Call notification channel for a user returns "Created" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV2::api_on_call::OnCallAPI;usedatadog_api_client::datadogV2::model::CreateEmailNotificationChannelConfig;usedatadog_api_client::datadogV2::model::CreateNotificationChannelAttributes;usedatadog_api_client::datadogV2::model::CreateNotificationChannelConfig;usedatadog_api_client::datadogV2::model::CreateNotificationChannelData;usedatadog_api_client::datadogV2::model::CreateUserNotificationChannelRequest;usedatadog_api_client::datadogV2::model::NotificationChannelEmailConfigType;usedatadog_api_client::datadogV2::model::NotificationChannelEmailFormatType;usedatadog_api_client::datadogV2::model::NotificationChannelType;#[tokio::main]asyncfnmain(){// there is a valid "user" in the system
letuser_data_id=std::env::var("USER_DATA_ID").unwrap();letbody=CreateUserNotificationChannelRequest::new(CreateNotificationChannelData::new(NotificationChannelType::NOTIFICATION_CHANNELS).attributes(CreateNotificationChannelAttributes::new().config(CreateNotificationChannelConfig::CreateEmailNotificationChannelConfig(Box::new(CreateEmailNotificationChannelConfig::new("foo@bar.com".to_string(),vec![NotificationChannelEmailFormatType::HTML],NotificationChannelEmailConfigType::EMAIL,),)),)),);letconfiguration=datadog::Configuration::new();letapi=OnCallAPI::with_config(configuration);letresp=api.create_user_notification_channel(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 channel for a user returns "Created" response
*/import{client,v2}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv2.OnCallApi(configuration);// there is a valid "user" in the system
constUSER_DATA_ID=process.env.USER_DATA_IDasstring;constparams: v2.OnCallApiCreateUserNotificationChannelRequest={body:{data:{attributes:{config:{address:"foo@bar.com",formats:["html"],type:"email",},},type:"notification_channels",},},userId: USER_DATA_ID,};apiInstance.createUserNotificationChannel(params).then((data: v2.NotificationChannel)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));