Skip to content

Commit e34e86e

Browse files
Update GetUsageSummary example to show AdditionalProperties access at all layers
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 479c479 commit e34e86e

2 files changed

Lines changed: 37 additions & 54 deletions

File tree

‎examples/v1/usage-metering/GetUsageSummary.py‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,48 @@
44

55
from datadog_api_client import ApiClient, Configuration
66
from datadog_api_client.v1.api.usage_metering_api import UsageMeteringApi
7+
from datadog_api_client.v2.api.usage_metering_api import UsageMeteringApi as UsageMeteringApiV2
78
from datetime import datetime
89
from dateutil.tz import tzutc
910

1011
configuration = Configuration()
1112
with ApiClient(configuration) as api_client:
12-
api_instance = UsageMeteringApi(api_client)
13-
response = api_instance.get_usage_summary(
13+
# Step 1: fetch the canonical field lists from the v2 discovery endpoint.
14+
v2_instance = UsageMeteringApiV2(api_client)
15+
fields_response = v2_instance.get_usage_summary_available_fields()
16+
attrs = fields_response.data.attributes
17+
response_fields = attrs.response_fields # Layer 1 keys
18+
date_fields = attrs.date_fields # Layer 2 keys
19+
date_org_fields = attrs.date_org_fields # Layer 3 keys
20+
21+
# Step 2: call the v1 summary endpoint with org details included.
22+
v1_instance = UsageMeteringApi(api_client)
23+
resp = v1_instance.get_usage_summary(
1424
start_month=datetime(2021, 11, 11, 11, 11, 11, 111000, tzinfo=tzutc()),
25+
include_org_details=True,
1526
)
1627

17-
print(response)
28+
# Layer 1 – top-level UsageSummaryResponse additionalProperties
29+
print("=== Layer 1: UsageSummaryResponse ===")
30+
for field in response_fields:
31+
value = resp.get(field)
32+
if value is not None:
33+
print(f" {field}: {value}")
34+
35+
# Layer 2 – per-date UsageSummaryDate additionalProperties
36+
print("=== Layer 2: UsageSummaryDate (usage[]) ===")
37+
for date_entry in resp.get("usage") or []:
38+
date_label = date_entry.get("date", "unknown")
39+
for field in date_fields:
40+
value = date_entry.get(field)
41+
if value is not None:
42+
print(f" [{date_label}] {field}: {value}")
43+
44+
# Layer 3 – per-org UsageSummaryDateOrg additionalProperties
45+
print(f" === Layer 3: UsageSummaryDateOrg (usage[].orgs[]) for {date_label} ===")
46+
for org in date_entry.get("orgs") or []:
47+
org_label = org.get("name", org.get("id", "unknown"))
48+
for field in date_org_fields:
49+
value = org.get(field)
50+
if value is not None:
51+
print(f" [{org_label}] {field}: {value}")

‎examples/v1/usage-metering/GetUsageSummary_additional_properties.py‎

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)