Skip to main content

dd_api/
dashboards.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4use crate::client::Client;
5use crate::error::Result;
6
7pub const DASHBOARD_PATH: &str = "api/v1/dashboard";
8
9/// One row of `GET /api/v1/dashboard`'s `dashboards` array.
10#[derive(Debug, Clone, Deserialize, Serialize)]
11pub struct DashboardSummary {
12    pub id: String,
13    #[serde(default)]
14    pub title: Option<String>,
15    #[serde(default)]
16    pub url: Option<String>,
17    #[serde(default)]
18    pub author_handle: Option<String>,
19    #[serde(default)]
20    pub description: Option<String>,
21}
22
23#[derive(Debug, Clone, Deserialize)]
24pub struct DashboardListResponse {
25    #[serde(default)]
26    pub dashboards: Vec<DashboardSummary>,
27}
28
29impl Client {
30    /// Fetch a single dashboard definition. Returns the raw JSON so callers can
31    /// read widget queries (`widgets[].definition.requests[].q`) without us
32    /// modelling Datadog's large, evolving widget schema.
33    pub async fn dashboard_get(&self, id: &str) -> Result<Value> {
34        self.get_json(&format!("{DASHBOARD_PATH}/{id}"), &[]).await
35    }
36
37    /// List all dashboards. The v1 endpoint has no server-side title search, so
38    /// title filtering is done client-side by the caller.
39    pub async fn dashboards_list(&self) -> Result<DashboardListResponse> {
40        self.get_json(DASHBOARD_PATH, &[]).await
41    }
42}