76
curl -H 'Accept: application/json' -H "Authorization: Bearer <token>" https://app.netdata.cloud/api/v2/data?contexts=system.cpu&after=-600
77
```
78
79
+**Advanced Metric Queries with Aggregation**
80
+
81
+For more advanced queries with aggregation, use the POST endpoint with a JSON body. This allows you to query metrics with time aggregation (like average values) and control grouping and filtering.
82
+
83
+```console
84
+TOKEN="YOUR_API_TOKEN"
85
+SPACE="YOUR_SPACE_ID"
86
+ROOM="YOUR_ROOM_ID"
87
+
88
+read -r -d '' PAYLOAD <<'EOF'
89
+{
90
+ "scope": {"contexts": ["system.cpu"]},
91
+ "selectors": {"nodes": ["*"], "contexts": ["*"], "instances": ["*"], "dimensions": ["*"], "labels": ["*"], "alerts": ["*"]},
92
+ "window": {"after": -600, "before": 0, "points": 5},
93
+ "aggregations": {
94
+ "metrics": [{"group_by": ["selected"], "aggregation": "sum"}],
95
+ "time": {"time_group": "average"}
96
+ },
97
+ "format": "json2",
98
+ "options": ["jsonwrap", "minify", "unaligned"],
99
+ "timeout": 30000
100
+}
101
+EOF
102
+
103
+curl -s -X POST \
104
+ -H 'Content-Type: application/json' \
105
+ -H "Authorization: Bearer $TOKEN" \
106
+ "https://app.netdata.cloud/api/v3/spaces/$SPACE/rooms/$ROOM/data" \
107
+ -d "$PAYLOAD"
108
+```
109
+
110
+**Time Aggregation Options**
111
+
112
+The `time_group` parameter in `aggregations.time` controls how data points within each time interval are combined:
113
+
114
+| Option | Description | Use Case |
115
+|--------|-------------|----------|
116
+| `average` | Mean value (default) | Average resource consumption over time |
117
+| `min` | Minimum value | Find lowest values in each interval |
118
+| `max` | Maximum value | Find spikes or peaks |
119
+| `sum` | Sum of values | Total volume transferred (counters) |
120
+| `median` | Median value | Robust central tendency |
121
+| `stddev` | Standard deviation | Measure of variability |
122
+| `ses` | Single exponential smoothing | Trend-aware smoothing |
123
+| `des` | Double exponential smoothing | Trend + seasonality smoothing |
124
+| `incremental-sum` | Difference between last and first value | Change over interval |
125
+| `percentile` | Generic percentile (set value in `time_group_options`) | e.g., 95th percentile latency |
126
+| `countif` | Count values matching condition (set condition in `time_group_options`) | e.g., count samples above threshold |
127
+| `trimmed-mean` | Mean after trimming outliers (set trim % in `time_group_options`) | Robust average excluding extremes |
128
+| `trimmed-median` | Median after trimming outliers (set trim % in `time_group_options`) | Robust median excluding extremes |
129
+| `extremes` | Min and max values | Show value range per interval |
130
+
131
+:::important
132
+
133
+When using `time_group` values other than `min`, `max`, `average`, or `sum`, you MUST specify `"tier": 0` in the `window` object to ensure a non-aggregated storage tier is used. Without it, the query may use a pre-aggregated tier (per-minute or per-hour) where advanced functions like `median`, `stddev`, `ses`, `des`, `percentile`, `countif`, `trimmed-mean`, `trimmed-median`, and `extremes` cannot work correctly.
134
+
135
+:::
136
+
137
**Get context information**
138
139
```console