v2_incidents_CreateIncident/
v2_incidents_CreateIncident.rs1use datadog_api_client::datadog;
3use datadog_api_client::datadogV2::api_incidents::IncidentsAPI;
4use datadog_api_client::datadogV2::model::IncidentCreateAttributes;
5use datadog_api_client::datadogV2::model::IncidentCreateData;
6use datadog_api_client::datadogV2::model::IncidentCreateRelationships;
7use datadog_api_client::datadogV2::model::IncidentCreateRequest;
8use datadog_api_client::datadogV2::model::IncidentFieldAttributes;
9use datadog_api_client::datadogV2::model::IncidentFieldAttributesSingleValue;
10use datadog_api_client::datadogV2::model::IncidentFieldAttributesSingleValueType;
11use datadog_api_client::datadogV2::model::IncidentType;
12use datadog_api_client::datadogV2::model::NullableRelationshipToUser;
13use datadog_api_client::datadogV2::model::NullableRelationshipToUserData;
14use datadog_api_client::datadogV2::model::UsersType;
15use std::collections::BTreeMap;
16
17#[tokio::main]
18async fn main() {
19 let user_data_id = std::env::var("USER_DATA_ID").unwrap();
21 let body = IncidentCreateRequest::new(
22 IncidentCreateData::new(
23 IncidentCreateAttributes::new(false, "Example-Incident".to_string()).fields(
24 BTreeMap::from([(
25 "state".to_string(),
26 IncidentFieldAttributes::IncidentFieldAttributesSingleValue(Box::new(
27 IncidentFieldAttributesSingleValue::new()
28 .type_(IncidentFieldAttributesSingleValueType::DROPDOWN)
29 .value(Some("resolved".to_string())),
30 )),
31 )]),
32 ),
33 IncidentType::INCIDENTS,
34 )
35 .relationships(IncidentCreateRelationships::new(Some(
36 NullableRelationshipToUser::new(Some(NullableRelationshipToUserData::new(
37 user_data_id.clone(),
38 UsersType::USERS,
39 ))),
40 ))),
41 );
42 let mut configuration = datadog::Configuration::new();
43 configuration.set_unstable_operation_enabled("v2.CreateIncident", true);
44 let api = IncidentsAPI::with_config(configuration);
45 let resp = api.create_incident(body).await;
46 if let Ok(value) = resp {
47 println!("{:#?}", value);
48 } else {
49 println!("{:#?}", resp.unwrap_err());
50 }
51}