This endpoint allows you to add new tags to a host,
optionally specifying what source these tags come from. If tags already exist, appends new tags to the tag list. If no source is specified, defaults to “user”.
"""
Add tags to a host returns "Created" response
"""fromdatadog_api_clientimportApiClient,Configurationfromdatadog_api_client.v1.api.tags_apiimportTagsApifromdatadog_api_client.v1.model.host_tagsimportHostTagsbody=HostTags(host="test.host",tags=["environment:production",],)configuration=Configuration()withApiClient(configuration)asapi_client:api_instance=TagsApi(api_client)response=api_instance.create_host_tags(host_name="host_name",body=body)print(response)
# Add tags to a host returns "Created" responserequire"datadog_api_client"api_instance=DatadogAPIClient::V1::TagsAPI.newbody=DatadogAPIClient::V1::HostTags.new({host:"test.host",tags:["environment:production",],})papi_instance.create_host_tags("host_name",body)
// Add tags to a host 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/datadogV1")funcmain(){body:=datadogV1.HostTags{Host:datadog.PtrString("test.host"),Tags:[]string{"environment:production",},}ctx:=datadog.NewDefaultContext(context.Background())configuration:=datadog.NewConfiguration()apiClient:=datadog.NewAPIClient(configuration)api:=datadogV1.NewTagsApi(apiClient)resp,r,err:=api.CreateHostTags(ctx,"host_name",body,*datadogV1.NewCreateHostTagsOptionalParameters())iferr!=nil{fmt.Fprintf(os.Stderr,"Error when calling `TagsApi.CreateHostTags`: %v\n",err)fmt.Fprintf(os.Stderr,"Full HTTP response: %v\n",r)}responseContent,_:=json.MarshalIndent(resp,""," ")fmt.Fprintf(os.Stdout,"Response from `TagsApi.CreateHostTags`:\n%s\n",responseContent)}
// Add tags to a host returns "Created" response
usedatadog_api_client::datadog;usedatadog_api_client::datadogV1::api_tags::CreateHostTagsOptionalParams;usedatadog_api_client::datadogV1::api_tags::TagsAPI;usedatadog_api_client::datadogV1::model::HostTags;#[tokio::main]asyncfnmain(){letbody=HostTags::new().host("test.host".to_string()).tags(vec!["environment:production".to_string()]);letconfiguration=datadog::Configuration::new();letapi=TagsAPI::with_config(configuration);letresp=api.create_host_tags("host_name".to_string(),body,CreateHostTagsOptionalParams::default(),).await;ifletOk(value)=resp{println!("{:#?}",value);}else{println!("{:#?}",resp.unwrap_err());}}
DD_SITE="datadoghq.comus3.datadoghq.comus5.datadoghq.comdatadoghq.euap1.datadoghq.comap2.datadoghq.comddog-gov.comus2.ddog-gov.com"DD_API_KEY="<API-KEY>"DD_APP_KEY="<APP-KEY>"cargo run
/**
* Add tags to a host returns "Created" response
*/import{client,v1}from"@datadog/datadog-api-client";constconfiguration=client.createConfiguration();constapiInstance=newv1.TagsApi(configuration);constparams: v1.TagsApiCreateHostTagsRequest={body:{host:"test.host",tags:["environment:production"],},hostName:"host_name",};apiInstance.createHostTags(params).then((data: v1.HostTags)=>{console.log("API called successfully. Returned data: "+JSON.stringify(data));}).catch((error: any)=>console.error(error));