Database-BI
view release on metacpan or search on metacpan
website/html/api.html view on Meta::CPAN
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>API — Database::BI</title>
<meta name="description" content="The JSON API behind Database::BI: saved canvases, their visuals, and the endpoints for columns, directories, statistics, questions and stored fields.">
<meta name="theme-color" content="#fbfaf7" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#12161b" media="(prefers-color-scheme: dark)">
<link rel="canonical" href="api.html">
<meta property="og:type" content="article">
<meta property="og:site_name" content="Database::BI">
<meta property="og:title" content="API — Database::BI">
<meta property="og:description" content="The JSON API behind Database::BI: saved canvases, their visuals, and the endpoints for columns, directories, statistics, questions and stored fields.">
<meta name="twitter:card" content="summary">
<link rel="stylesheet" href="../css/site.css">
</head>
<body>
<a class="skip" href="#main">Skip to content</a>
<header class="site-header">
<div class="wrap header-inner">
<a class="brand" href="index.html">
<span class="brand-name">Database::BI</span>
<span class="brand-tag">business intelligence for data files</span>
</a>
<nav class="site-nav" aria-label="Main">
<a href="index.html">Overview</a>
<a href="charts.html">Charts</a>
<a href="canvas.html">Canvases</a>
<a href="data.html">Data</a>
<a href="api.html" aria-current="page">API</a>
<a href="install.html">Install</a>
</nav>
</div>
</header>
<main id="main" class="wrap">
<div class="hero">
<p class="eyebrow">JSON, same process, same files</p>
<h1>API</h1>
<p class="lead">
Every page is built from the same pipeline, and the interesting parts are
available as JSON: saved canvases, their cards, the columns of a source,
the filesystem, stored calculated fields and the optional question and
summary endpoints.
</p>
</div>
<p>
With <a href="install.html#login"><code>password_hash</code></a> set, every
endpoint here needs the login: a request without the session cookie gets 401
<code>{ "error": ... }</code>. A write sent by another site's page is refused
with 403 either way (<a href="install.html#other-sites">Requests from other
sites</a>).
</p>
<h2 id="canvases">Saved canvases</h2>
<div class="table-wrap">
<table>
<thead>
<tr><th>Method and path</th><th>Does</th><th>Answers</th></tr>
</thead>
<tbody>
<tr>
<td><code>GET /api/analyses</code></td>
<td>Lists every saved canvas.</td>
<td><code>{ analyses: [{ id, name, datasets, updated }] }</code></td>
</tr>
<tr>
<td><code>POST /api/analyses</code></td>
<td>Creates one. Needs <code>name</code> and <code>datasets</code>; each dataset needs a <code>spec</code> starting <code>table:</code>, <code>path:</code>, <code>url:</code> or <code>redis:</code>, or being <code>mariadb:server/table</code>.</td>
<td><code>201 { id, created: 1 }</code></td>
</tr>
<tr>
<td><code>GET /api/analyses/:id</code></td>
<td>Returns the whole document.</td>
<td>The canvas</td>
</tr>
<tr>
<td><code>PUT /api/analyses/:id</code></td>
<td>Replaces the document.</td>
<td>The saved canvas</td>
</tr>
<tr>
<td><code>PATCH /api/analyses/:id</code></td>
<td>Merges the supplied top-level keys. <code>id</code> and <code>created</code> are immutable; unknown keys are dropped.</td>
<td>The saved canvas</td>
</tr>
<tr>
<td><code>DELETE /api/analyses/:id</code></td>
<td>Removes it.</td>
<td><code>{ deleted: 1 }</code></td>
</tr>
<tr>
<td><code>GET /api/analyses/:id/export</code></td>
<td>Downloads the document.</td>
<td>A <code>.json</code> file</td>
</tr>
<tr>
<td><code>POST /api/analyses/import</code></td>
<td>Creates one from an uploaded <code>.json</code> file or a raw JSON body. Caller-supplied <code>id</code>, <code>created</code> and <code>updated</code> are stripped.</td>
<td>The new canvas</td>
</tr>
<tr>
<td><code>POST /api/analyses/:id/share</code></td>
<td>Issues a share token for the canvas.</td>
<td>A share link</td>
</tr>
</tbody>
</table>
</div>
website/html/api.html view on Meta::CPAN
A text card reads no data, so it has no <code>encode</code>, <code>query</code>
or <code>cross_row</code>, and <code>/a/:id/visual/:n/csv</code> answers 404 for
it. A setting outside these is dropped; one with a bad value is a 400 and nothing
is stored.
</p>
<dl class="spec">
<dt><code>text</code></dt>
<dd>Required, up to 20,000 characters. It is shown as plain text, never as markup.</dd>
<dt><code>font</code></dt>
<dd><code>arial</code>, <code>georgia</code>, <code>times</code>, <code>verdana</code>, <code>trebuchet</code> or <code>courier</code>. Left out, the card uses the page's font.</dd>
<dt><code>size</code></dt>
<dd>A whole number of points from 8 to 96.</dd>
<dt><code>colour</code>, <code>background</code></dt>
<dd>Written <code>#rrggbb</code>. Left out, the text follows the theme and the card has no fill of its own.</dd>
<dt><code>align</code></dt>
<dd><code>left</code>, <code>center</code> or <code>right</code>.</dd>
<dt><code>bold</code>, <code>italic</code>, <code>plain</code></dt>
<dd>True to turn on. <code>plain</code> hides the frame and header until the card is pointed at.</dd>
</dl>
<pre><code>PATCH /api/analyses/:id/visuals/:visual { "options": { ... } }
DELETE /api/analyses/:id/visuals/:visual</code></pre>
<p>
PATCH replaces all the options, keeping the card's place and size. DELETE answers
<code>{ "deleted": 1 }</code>; it accepts only text cards, and any other kind is a
400. Later cards move down one index, and the layout and any <code>cv</code> in a
bookmark move with them.
</p>
<h2 id="data">Data and filesystem</h2>
<dl class="spec">
<dt><code>GET /api/columns?table=…</code> or <code>?path=…</code></dt>
<dd>The column names of a source, used to populate the join panel without a page reload.</dd>
<dt><code>GET /api/dirs?path=…</code></dt>
<dd>Subdirectories of a path, for the export panel's inline browser. With <code>export_dirs</code> set it starts at the first and lists only those folders and below; with <code>file_roots</code>, only those. A path outside is 403 (<a href="install.h...
<dt><code>GET /api/stat?path=…</code></dt>
<dd><code>{ exists, path, mtime, size }</code>, plus <code>table_count</code> for a valid SQLite file.</dd>
<dt><code>GET /api/range?l=…</code></dt>
<dd>The earliest and latest value of a date column, so the filter bar can disable a window the data cannot answer.</dd>
<dt><code>POST /api/ask</code></dt>
<dd>
A question in words, answered with an analysis spec and a URL. The model
sees column names and types only — never rows or file paths. 503 when
no key is configured, 422 when the question cannot be mapped to valid
columns. 400 when the question is over 500 characters, and 429 once the
server has made <code>ai_calls_per_hour</code> provider calls in the last hour
(default 60, shared with the summary).
</dd>
<dt><code>POST /api/summary</code></dt>
<dd>
A narrative summary from deterministic sentences, works offline, with an
optional polished version when <code>ai=1</code> and a key is set. Cached
for an hour. Past <code>ai_calls_per_hour</code> it gives the deterministic
text, with <code>source</code> <code>template_limited</code>, uncached.
</dd>
</dl>
<h2 id="stored">Stored fields</h2>
<p>
The definitions saved beside the data — calculated fields, value groups,
date patterns, lookups, extractions and coordinate columns — have a list, a save and a delete
endpoint each, all keyed by <code>l=<spec></code>:
</p>
<div class="table-wrap">
<table>
<thead>
<tr><th>Area</th><th>List</th><th>Save</th><th>Delete</th></tr>
</thead>
<tbody>
<tr>
<td>Calculated fields</td>
<td><code>GET /calc/list</code></td>
<td><code>POST /calc/save</code> (<code>name</code>, <code>expr</code>)</td>
<td><code>POST /calc/delete</code></td>
</tr>
<tr>
<td>Value groups</td>
<td><code>GET /groups/list</code></td>
<td><code>POST /groups/save</code> (<code>group</code>, <code>values</code>)</td>
<td><code>POST /groups/delete</code></td>
</tr>
<tr>
<td>Date patterns</td>
<td><code>GET /dates/list</code></td>
<td><code>POST /dates/save</code> (<code>pattern</code>, optional <code>time</code>, <code>as</code>)</td>
<td><code>POST /dates/delete</code></td>
</tr>
<tr>
<td>Lookups (<a href="data.html#lookups">how they apply</a>)</td>
<td><code>GET /lookups/list</code></td>
<td><code>POST /lookups/save</code> (<code>name</code>, <code>file</code>, <code>key</code>, optional <code>col</code>, <code>fields</code>, <code>default</code>)</td>
<td><code>POST /lookups/delete</code></td>
</tr>
<tr>
<td>Field extractions (<a href="data.html#extract">how they apply</a>)</td>
<td><code>GET /extract/list</code></td>
<td><code>POST /extract/save</code> (<code>name</code>, <code>col</code>, <code>pattern</code>, optional <code>fields</code>)</td>
<td><code>POST /extract/delete</code></td>
</tr>
<tr>
<td>Coordinate columns</td>
<td><code>GET /geo/list</code></td>
<td><code>POST /geo/save</code> (<code>col</code>, <code>kind</code>, repeatable in pairs; <code>replace=1</code> forgets the old ones first; <code>loc_text</code>, the text added to each place)</td>
<td><code>POST /geo/delete</code></td>
</tr>
</tbody>
</table>
</div>
<h2>Behaviour to rely on</h2>
<ul class="plain">
<li>
A missing canvas, table or route answers 404: HTML for a page, JSON for
anything under <code>/api/</code>.
</li>
<li>
Error replies that quote a parameter are sent as plain text, not HTML, so a
crafted link cannot run script on the site through an error message.
</li>
<li>
A write to <code>analyses.json</code> that cannot be saved answers 503
rather than reporting a success that did not happen.
( run in 1.170 second using v1.01-cache-2.11-cpan-eb134014566 )