Skip to content

[Dashboards] Add programmatic creation docs and API examples#5770

Closed
florent-leborgne wants to merge 9 commits into
mainfrom
add/dashboards-api-docs
Closed

[Dashboards] Add programmatic creation docs and API examples#5770
florent-leborgne wants to merge 9 commits into
mainfrom
add/dashboards-api-docs

Conversation

@florent-leborgne
Copy link
Copy Markdown
Member

Summary

This PR adds documentation for creating Kibana dashboards and visualizations programmatically, as a companion to elastic/kibana#259842 (Visualizations API) and the pending Dashboards API Kibana PR.

New page: explore-analyze/dashboards/create-programmatically.md — covers the Dashboards API, the Lens Visualizations API, the kibana-dashboards agent skill, and the upcoming Agent Builder dashboard tools. All API content is gated at preview 9.4.

Updated pages:

  • explore-analyze/dashboards/building.md — adds a pointer to the new programmatic page
  • explore-analyze/dashboards/create-dashboard.md — adds a collapsible API dropdown after the agent-skill callout
  • explore-analyze/kibana-data-exploration-learning-tutorial.md — adds a forward link in Step 3 and a full API dropdown at the end of the step, so learners can discover the API without skipping the manual tutorial

Notes

  • All API examples use applies_to: stack: preview 9.4 / serverless: preview
  • API payloads were validated against Kibana main branch
  • The Agent Builder tools section references [Epic] Dashboards in chat - Tech Preview kibana#237795 (tech preview, dashboard tools coming in 9.4)
  • The kibana-dashboards agent skill is already linked from create-dashboard.md via the {agent-skill} directive; this PR adds a dedicated section in the new overview page

Test plan

  • Verify applies_to badges render correctly on all modified pages
  • Verify dropdown directives render and collapse correctly
  • Verify all links to API reference resolve
  • Verify toc.yml addition shows create-programmatically.md in the nav

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 2, 2026

✅ Vale Linting Results

No issues found on modified lines!


The Vale linter checks documentation changes against the Elastic Docs style guide.

To use Vale locally or report issues, refer to Elastic style guide for Vale.

@florent-leborgne
Copy link
Copy Markdown
Member Author

Superseded by #6337. The original draft on this branch was based on the pre-restructure layout of the dashboards programmatic-creation docs and used the old API schema (type: lens, dataset, operation-style x/y). After #5927 split the page into create-dashboards-programmatically.md + create-dashboards-using-ai.md and the Dashboards API tightened its schema, the diff here doesn't apply cleanly. #6337 ports only the still-relevant work — the curl POST in the data-exploration tutorial — onto the new structure, against the verified current schema, with a verification script to keep it honest going forward.

florent-leborgne added a commit that referenced this pull request May 13, 2026
…e Dashboards API (#6337)

## Summary

I want to introduce the API in the Kibana analytics learning tutorial.
The idea is:
-> new users try kibana, learn about discover, dashboards, and the paths
between the 2, they end up with a dashboard that they understand, then
we show that this is also all reproducible using the API, once they have
the main concepts of dashboards in mind.

Preview:
https://docs-v3-preview.elastic.dev/elastic/docs-content/pull/6337/explore-analyze/kibana-data-exploration-learning-tutorial

Closes the remaining checklist items of #5822 by adding an **`##
(Optional) Recreate the dashboard with the API`** section to
`explore-analyze/kibana-data-exploration-learning-tutorial.md`. The
first checklist item (the **Create programmatically** overview page) was
completed by #5927.

The section is placed after Step 4 (Share), once the four-step tutorial
narrative is complete, so it reads as a capstone rather than
interrupting the step sequence. It carries `applies_to` badges (`stack:
preview 9.4+`, `serverless: preview`) and a two-sentence intro, then
collapses the full payload into a **Recreate this dashboard with one API
call** dropdown.

The dropdown contains one curl POST to `/api/dashboards` that recreates
the finished tutorial dashboard, including the optional panels suggested
across Step 3 (extra metrics, response size over time, pie, treemap).
Eleven explicit `<n>` code callouts anchor each JSON panel to the
tutorial sub-step that introduced it; the numbered list after the curl
block highlights the non-obvious API patterns (`breakdown_by`,
`reference_lines` as a separate layer, ES|QL `column` references in `xy`
`x`/`y`, `rows` vs `metrics` in ES|QL data tables, pie/treemap with
`metrics` + `group_by`).

The page from #5927 already covers the **API payload dropdown on the
Create dashboard page** (item 2 of #5822) via the existing _New ways to
create dashboards_ tip, so no edit is needed on `create-dashboard.md`.

This supersedes #5770, which was drafted before the spec restructure
landed.

## Verification

The Dashboards API is in technical preview (`x-state: Technical Preview;
added in 9.4.0`), so the embedded payload was rebuilt against the
current `dashboards-api-spec` (commit `84120e3`); the old draft used the
pre-restructure schema (`type: lens`, `dataset`, operation-style x/y)
which the API no longer accepts.

The current payload was POSTed end-to-end against a live serverless
instance. HTTP 201, 11 panels created, panel set matches a fresh export
from a manually-built tutorial dashboard. Schema details verified
directly against `openapi/kibana-openapi.yaml`:

- panel-level type `vis` with `config.type` (not `lens`)
- `data_source` with `data_view_spec` or `esql` (not `dataset`)
- ES|QL chart layers reference query result columns via `x.column` /
`y[].column`
- xy bar default is `bar_stacked` (matches Lens)
- reference lines as a sibling layer of type `reference_lines` with
`thresholds`
- metric secondary with `time_shift` + `compare`
- ES|QL `data_table` with `rows` (categorical) and `metrics` (values)

## Maintenance

To keep the example honest as the schema evolves, this PR also adds:

1. An HTML maintenance comment above the dropdown noting the spec
source, last-verified commit, and pointer to the verification script.
2. `.github/scripts/verify-dashboards-api-example.py`, a stdlib-only
Python script that extracts the curl JSON from the markdown, strips
`<n>` callouts, POSTs it against `\${KIBANA_URL}` with `\${API_KEY}`,
asserts HTTP 201 + the expected panel count, then deletes the test
dashboard.

Anyone editing the example can run:

```bash
KIBANA_URL=… API_KEY=… python3 .github/scripts/verify-dashboards-api-example.py
```

The script is designed to be promoted to a `workflow_dispatch` GitHub
Action against a CI Kibana later if we want continuous drift detection.

## Test plan

- [ ] Preview renders the optional section after Step 4, with the
dropdown collapsed by default
- [ ] `applies_to` badges on the section show preview / 9.4+
- [ ] Code callouts `<1>`–`<11>` render as styled badges aligned with
the corresponding panel titles/labels
- [ ] All links resolve:
`dashboards/create-dashboards-programmatically.md`, the in-page
`#explore-data-in-discover` anchor, the external Dashboards API
reference
- [ ] `python3 .github/scripts/verify-dashboards-api-example.py` exits 0
against a Kibana 9.4+ instance with the sample logs dataset installed
- [ ] Vale passes

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Benjamin Ironside Goldstein <91905639+benironside@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Dashboards API documentation to dashboards narrative docs

1 participant