From 0315f711b82f1d240238e7cd5087b7694679f69f Mon Sep 17 00:00:00 2001 From: Charlie Zhang Date: Mon, 15 Jun 2026 14:21:43 -0400 Subject: [PATCH 1/3] feat: add example for UsageSummary additionalProperties iteration Adds a new example demonstrating how to call GetUsageSummaryAvailableFields (v2) to enumerate available field names, then call GetUsageSummary (v1) and iterate those fields over additionalProperties at the response, date, and org layers. Co-Authored-By: Claude Sonnet 4.6 --- ...g_GetUsageSummary_additional_properties.rs | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 examples/v1_usage-metering_GetUsageSummary_additional_properties.rs diff --git a/examples/v1_usage-metering_GetUsageSummary_additional_properties.rs b/examples/v1_usage-metering_GetUsageSummary_additional_properties.rs new file mode 100644 index 000000000..d8107e3d1 --- /dev/null +++ b/examples/v1_usage-metering_GetUsageSummary_additional_properties.rs @@ -0,0 +1,93 @@ +// Get usage across your account and read all fields from additionalProperties returns "OK" response +use chrono::{DateTime, Utc}; +use datadog_api_client::datadog; +use datadog_api_client::datadogV1::api_usage_metering::GetUsageSummaryOptionalParams; +use datadog_api_client::datadogV1::api_usage_metering::UsageMeteringAPI; +use datadog_api_client::datadogV2::api_usage_metering::UsageMeteringAPI as UsageMeteringAPIV2; + +#[tokio::main] +async fn main() { + let configuration = datadog::Configuration::new(); + + // Step 1: call v2 GetUsageSummaryAvailableFields to learn which keys exist + let api_v2 = UsageMeteringAPIV2::with_config(configuration.clone()); + let fields_resp = api_v2.get_usage_summary_available_fields().await; + let (response_fields, date_fields, date_org_fields) = match fields_resp { + Ok(body) => { + let attrs = body + .data + .and_then(|d| d.attributes) + .unwrap_or_default(); + ( + attrs.response_fields.unwrap_or_default(), + attrs.date_fields.unwrap_or_default(), + attrs.date_org_fields.unwrap_or_default(), + ) + } + Err(e) => { + println!("{:#?}", e); + return; + } + }; + + // Step 2: call v1 GetUsageSummary with include_org_details + let api_v1 = UsageMeteringAPI::with_config(configuration); + let resp = api_v1 + .get_usage_summary( + DateTime::parse_from_rfc3339("2021-11-11T11:11:11.111000+00:00") + .expect("Failed to parse datetime") + .with_timezone(&Utc), + GetUsageSummaryOptionalParams::default().include_org_details(true), + ) + .await; + + let summary = match resp { + Ok(value) => value, + Err(e) => { + println!("{:#?}", e); + return; + } + }; + + // Step 3: iterate response_fields over top-level UsageSummaryResponse additional_properties + println!("=== response-level additional_properties ==="); + for field in &response_fields { + if let Some(val) = summary.additional_properties.get(field) { + println!(" {field}: {val}"); + } + } + + // Step 4: iterate date_fields and date_org_fields over each UsageSummaryDate (and its orgs) + if let Some(usage_dates) = &summary.usage { + for usage_date in usage_dates { + println!( + "\n=== date {} additional_properties ===", + usage_date + .date + .map(|d| d.to_string()) + .unwrap_or_else(|| "(unknown)".to_string()) + ); + for field in &date_fields { + if let Some(val) = usage_date.additional_properties.get(field) { + println!(" {field}: {val}"); + } + } + + if let Some(orgs) = &usage_date.orgs { + for org in orgs { + println!( + "\n === org {} additional_properties ===", + org.name + .as_deref() + .unwrap_or("(unknown)") + ); + for field in &date_org_fields { + if let Some(val) = org.additional_properties.get(field) { + println!(" {field}: {val}"); + } + } + } + } + } + } +} From 1caec61f875558d03cec3fb8dda8736c672da848 Mon Sep 17 00:00:00 2001 From: Charlie Zhang Date: Mon, 15 Jun 2026 14:27:05 -0400 Subject: [PATCH 2/3] Update GetUsageSummary example to show AdditionalProperties access at all layers Co-Authored-By: Claude Sonnet 4.6 --- examples/v1_usage-metering_GetUsageSummary.rs | 83 +++++++++++++++-- ...g_GetUsageSummary_additional_properties.rs | 93 ------------------- 2 files changed, 76 insertions(+), 100 deletions(-) delete mode 100644 examples/v1_usage-metering_GetUsageSummary_additional_properties.rs diff --git a/examples/v1_usage-metering_GetUsageSummary.rs b/examples/v1_usage-metering_GetUsageSummary.rs index 707b12b14..2f791ff63 100644 --- a/examples/v1_usage-metering_GetUsageSummary.rs +++ b/examples/v1_usage-metering_GetUsageSummary.rs @@ -3,22 +3,91 @@ use chrono::{DateTime, Utc}; use datadog_api_client::datadog; use datadog_api_client::datadogV1::api_usage_metering::GetUsageSummaryOptionalParams; use datadog_api_client::datadogV1::api_usage_metering::UsageMeteringAPI; +use datadog_api_client::datadogV2::api_usage_metering::UsageMeteringAPI as UsageMeteringAPIV2; #[tokio::main] async fn main() { let configuration = datadog::Configuration::new(); - let api = UsageMeteringAPI::with_config(configuration); - let resp = api + + // Step 1: call v2 GetUsageSummaryAvailableFields to learn which keys exist + let api_v2 = UsageMeteringAPIV2::with_config(configuration.clone()); + let fields_resp = api_v2.get_usage_summary_available_fields().await; + let (response_fields, date_fields, date_org_fields) = match fields_resp { + Ok(body) => { + let attrs = body + .data + .and_then(|d| d.attributes) + .unwrap_or_default(); + ( + attrs.response_fields.unwrap_or_default(), + attrs.date_fields.unwrap_or_default(), + attrs.date_org_fields.unwrap_or_default(), + ) + } + Err(e) => { + println!("{:#?}", e); + return; + } + }; + + // Step 2: call v1 GetUsageSummary with include_org_details + let api_v1 = UsageMeteringAPI::with_config(configuration); + let resp = api_v1 .get_usage_summary( DateTime::parse_from_rfc3339("2021-11-11T11:11:11.111000+00:00") .expect("Failed to parse datetime") .with_timezone(&Utc), - GetUsageSummaryOptionalParams::default(), + GetUsageSummaryOptionalParams::default().include_org_details(true), ) .await; - if let Ok(value) = resp { - println!("{:#?}", value); - } else { - println!("{:#?}", resp.unwrap_err()); + + let summary = match resp { + Ok(value) => value, + Err(e) => { + println!("{:#?}", e); + return; + } + }; + + // Layer 1: iterate response_fields over top-level UsageSummaryResponse additional_properties + println!("=== response-level additional_properties ==="); + for field in &response_fields { + if let Some(val) = summary.additional_properties.get(field) { + println!(" {field}: {val}"); + } + } + + // Layer 2 & 3: iterate date_fields and date_org_fields over each UsageSummaryDate (and its orgs) + if let Some(usage_dates) = &summary.usage { + for usage_date in usage_dates { + println!( + "\n=== date {} additional_properties ===", + usage_date + .date + .map(|d| d.to_string()) + .unwrap_or_else(|| "(unknown)".to_string()) + ); + for field in &date_fields { + if let Some(val) = usage_date.additional_properties.get(field) { + println!(" {field}: {val}"); + } + } + + if let Some(orgs) = &usage_date.orgs { + for org in orgs { + println!( + "\n === org {} additional_properties ===", + org.name + .as_deref() + .unwrap_or("(unknown)") + ); + for field in &date_org_fields { + if let Some(val) = org.additional_properties.get(field) { + println!(" {field}: {val}"); + } + } + } + } + } } } diff --git a/examples/v1_usage-metering_GetUsageSummary_additional_properties.rs b/examples/v1_usage-metering_GetUsageSummary_additional_properties.rs deleted file mode 100644 index d8107e3d1..000000000 --- a/examples/v1_usage-metering_GetUsageSummary_additional_properties.rs +++ /dev/null @@ -1,93 +0,0 @@ -// Get usage across your account and read all fields from additionalProperties returns "OK" response -use chrono::{DateTime, Utc}; -use datadog_api_client::datadog; -use datadog_api_client::datadogV1::api_usage_metering::GetUsageSummaryOptionalParams; -use datadog_api_client::datadogV1::api_usage_metering::UsageMeteringAPI; -use datadog_api_client::datadogV2::api_usage_metering::UsageMeteringAPI as UsageMeteringAPIV2; - -#[tokio::main] -async fn main() { - let configuration = datadog::Configuration::new(); - - // Step 1: call v2 GetUsageSummaryAvailableFields to learn which keys exist - let api_v2 = UsageMeteringAPIV2::with_config(configuration.clone()); - let fields_resp = api_v2.get_usage_summary_available_fields().await; - let (response_fields, date_fields, date_org_fields) = match fields_resp { - Ok(body) => { - let attrs = body - .data - .and_then(|d| d.attributes) - .unwrap_or_default(); - ( - attrs.response_fields.unwrap_or_default(), - attrs.date_fields.unwrap_or_default(), - attrs.date_org_fields.unwrap_or_default(), - ) - } - Err(e) => { - println!("{:#?}", e); - return; - } - }; - - // Step 2: call v1 GetUsageSummary with include_org_details - let api_v1 = UsageMeteringAPI::with_config(configuration); - let resp = api_v1 - .get_usage_summary( - DateTime::parse_from_rfc3339("2021-11-11T11:11:11.111000+00:00") - .expect("Failed to parse datetime") - .with_timezone(&Utc), - GetUsageSummaryOptionalParams::default().include_org_details(true), - ) - .await; - - let summary = match resp { - Ok(value) => value, - Err(e) => { - println!("{:#?}", e); - return; - } - }; - - // Step 3: iterate response_fields over top-level UsageSummaryResponse additional_properties - println!("=== response-level additional_properties ==="); - for field in &response_fields { - if let Some(val) = summary.additional_properties.get(field) { - println!(" {field}: {val}"); - } - } - - // Step 4: iterate date_fields and date_org_fields over each UsageSummaryDate (and its orgs) - if let Some(usage_dates) = &summary.usage { - for usage_date in usage_dates { - println!( - "\n=== date {} additional_properties ===", - usage_date - .date - .map(|d| d.to_string()) - .unwrap_or_else(|| "(unknown)".to_string()) - ); - for field in &date_fields { - if let Some(val) = usage_date.additional_properties.get(field) { - println!(" {field}: {val}"); - } - } - - if let Some(orgs) = &usage_date.orgs { - for org in orgs { - println!( - "\n === org {} additional_properties ===", - org.name - .as_deref() - .unwrap_or("(unknown)") - ); - for field in &date_org_fields { - if let Some(val) = org.additional_properties.get(field) { - println!(" {field}: {val}"); - } - } - } - } - } - } -} From bdd6ae093ab41f58de0f446ff1d4a593adf2af8f Mon Sep 17 00:00:00 2001 From: Charlie Zhang Date: Mon, 15 Jun 2026 14:50:46 -0400 Subject: [PATCH 3/3] Update GetUsageSummaryAvailableFields example to print field lists by category --- ...metering_GetUsageSummaryAvailableFields.rs | 31 ++++++++++++++++--- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/examples/v2_usage-metering_GetUsageSummaryAvailableFields.rs b/examples/v2_usage-metering_GetUsageSummaryAvailableFields.rs index b27c739d2..c89896bf4 100644 --- a/examples/v2_usage-metering_GetUsageSummaryAvailableFields.rs +++ b/examples/v2_usage-metering_GetUsageSummaryAvailableFields.rs @@ -1,4 +1,4 @@ -// Get available fields for usage summary returns "OK." response +// Get available fields for usage summary returns "OK" response use datadog_api_client::datadog; use datadog_api_client::datadogV2::api_usage_metering::UsageMeteringAPI; @@ -7,9 +7,30 @@ async fn main() { let configuration = datadog::Configuration::new(); let api = UsageMeteringAPI::with_config(configuration); let resp = api.get_usage_summary_available_fields().await; - if let Ok(value) = resp { - println!("{:#?}", value); - } else { - println!("{:#?}", resp.unwrap_err()); + match resp { + Ok(value) => { + if let Some(data) = value.data { + if let Some(attrs) = data.attributes { + let response_fields = attrs.response_fields.unwrap_or_default(); + println!("response_fields ({}):", response_fields.len()); + for f in &response_fields { + println!(" {f}"); + } + + let date_fields = attrs.date_fields.unwrap_or_default(); + println!("date_fields ({}):", date_fields.len()); + for f in &date_fields { + println!(" {f}"); + } + + let date_org_fields = attrs.date_org_fields.unwrap_or_default(); + println!("date_org_fields ({}):", date_org_fields.len()); + for f in &date_org_fields { + println!(" {f}"); + } + } + } + } + Err(e) => println!("{:#?}", e), } }