Skip to content

Custom Insight Widgets

Custom Insight widgets put numbers from your own systems on an Insight dashboard, next to KnowledgeLake's own work-item metrics.

  1. You host a small HTTPS endpoint that returns JSON.
  2. An administrator registers it once as a Web Request source.
  3. Dashboard authors then add Custom Text, Custom Time Series or Custom Categorical widgets that read from it.

Use it when operations staff need a KPI, a daily trend or a breakdown that lives outside KnowledgeLake (an ERP exception queue, invoice volume, a backlog by vendor) on the dashboard they already watch.

At a glance

  • Runs On the KnowledgeLake server. Each time a dashboard loads the widget, KnowledgeLake calls your endpoint with HTTP GET. The viewer's browser never calls your endpoint.
  • Language any. Your endpoint returns JSON in the Custom Insight schema.
  • Authored in Connections > Sources (the Web Request source) and Insight > Dashboards (the widget).
  • Can reach Whatever your endpoint can reach. KnowledgeLake refuses hosts that resolve to local or private addresses.
  • Best for read-only KPIs, daily trends and category breakdowns from systems outside KnowledgeLake.

Choose a Custom Gizmo instead when the data belongs inside a task and the user must act on it. Choose Call External API when a workflow must send data out. Insight widgets only display data.

How it fits together

graph TD
  V["Viewer opens the dashboard"] --> D["Insight dashboard"]
  D --> W["Custom widget: Text, Time Series or Categorical"]
  W --> S["Web Request source: Endpoint URL, Bearer Token, Timeout"]
  S -->|GET with bearer token| E["Your endpoint"]
  E --> Y["Your data: ERP, database, queue"]
  E -->|Custom Insight JSON| S
  S --> K["Schema check on the KnowledgeLake server"]
  K --> W

The widget stores two things: which Web Request source to use, and an API Relative Path under the source's Endpoint URL. The source stores the URL, the token and the timeout. One endpoint can serve many widgets, one path each.

Runtime contract

Item Value
Engine Your HTTPS endpoint, in any language, on any host. The KnowledgeLake server calls it.
Runs when A dashboard that contains the widget opens, and when an author saves the dashboard. Test Connection and SAVE on the source call /validate. Get Available Series calls the data path with Series-Query: true.
Request GET {Endpoint URL}/{API Relative Path}, no body. Headers: Authorization: Bearer <token>, Creator-Token, Viewer-Token, Dashboard-Id, Dashboard-Name, Widget-Id, and Days-To-Include from Custom Time Series widgets.
Connection test GET {Endpoint URL}/validate with only the Authorization header. Must return exactly HTTP 200.
Response HTTP 2xx and JSON: { "version": "1.0", "type": "...", "data": { "values": [...] }, "browserCacheTTL": 300 }. KnowledgeLake validates it against the Custom Insight schema.
Timeout The source's Timeout (seconds), default 30.
Network access Public hosts only. Loopback, private, link-local and IPv6 local addresses are refused when the source is saved and on every request.
Caching The viewer's browser keeps the result for browserCacheTTL seconds. KnowledgeLake does not cache it on the server.
Permissions Connections Edit Configuration to create the source. Insight Create Dashboards to add the widget. Insight View Dashboards to see it.
Availability Insight must be enabled for your tenant. No other feature flag.

The full settings, headers and JSON shapes are on the Web Request Source Reference.

Rules

  1. Answer GET {Endpoint URL}/validate with HTTP 200 for the right token and HTTP 401 for any other. The source cannot be saved until this passes.
  2. Check the bearer token on every route, in constant time. Keep your copy in app settings or a key vault, never in code.
  3. Send version as the string "1.0", type equal to the widget's type (customtext, customtimeseries or customcategorical), and data.values as an array.
  4. Send dates as ISO 8601 UTC strings. For time series, send one row per day dated at midnight UTC (2026-10-07T00:00:00Z).
  5. In a time series row, every key except date is a series name with a number value. Leave a key out instead of sending null or a string.
  6. Answer well inside the Timeout. Every viewer's dashboard load calls you once per widget, so cache expensive queries in your endpoint and set browserCacheTTL.
  7. Serve only widget data on the Endpoint URL's host. A dashboard author can point a widget at any path on that host, with the source's token.
  8. Use Viewer-Token to filter what a viewer sees, not to authenticate the call. The bearer token is the authentication.
  9. Use HTTPS. The token travels in a header.

Gotchas

Mistakes that bite

  • "Showing Mock Data Until Save". A new or edited widget shows sample data until you save the dashboard. KnowledgeLake reads the saved widget settings, so your endpoint is not called before Save.
  • Custom Text stuck on Loading…. Your data.values array was empty. Always return at least one item.
  • Only the newest item shows. Custom Text shows the str with the newest date. Custom Categorical shows only the dataset with the newest date. Older items are ignored.
  • Two rows on one day. Custom Time Series keeps the last row for a UTC day; it does not add them. Group by day in your query.
  • Rates in a time series. Weekly, Monthly and Cumulative views add daily values. Send counts or totals, not averages or percentages.
  • Only two series appear. Get Available Series selects the first two names. Add the others in Visible Series, or clear it to show all.
  • Days-To-Include is missing. Only Custom Time Series widgets send it. Text and Categorical widgets get no date window.
  • "The request to the endpoint timed out." at once. The Endpoint URL's host does not resolve, or resolves to a private or local address. KnowledgeLake reports a timeout on purpose.
  • One error for many causes. A non-2xx status, a timeout and a refused host all show The custom insight endpoint could not be reached. Read your endpoint's log first.

Examples

  • KPI: Open Exceptions: a Custom Text widget that shows a Markdown KPI from your own exception queue. Teaches the smallest complete endpoint.
  • Daily Invoice Volume: a Custom Time Series widget with three series from an ERP table. Teaches Days-To-Include, one row per day, and the Series-Query probe.
  • Exceptions by Vendor or Queue: a Custom Categorical widget whose grouping comes from the API Relative Path. Teaches one endpoint for many widgets, and top N plus "Other".

Copy this into your assistant

Paste the block below into your AI assistant together with the AI Assistant Primer, then describe the widget you want and where its data lives. It is the same contract as this page, written for a model.

Custom Insight widgets context for AI assistants
# Custom Insight widgets: context for AI assistants

You build an HTTPS endpoint that feeds KnowledgeLake Insight dashboard widgets. Use only
the facts in this block. If you need a name the user has not given (data source, table, column,
route, app setting), ask for it. Never invent one.

## The surface
- An administrator creates a Web Request source: Connections > Sources > Add a Source, Source
  Type "Web Request". Settings: Endpoint URL (absolute http or https URL; use https), Bearer Token
  (stored encrypted), Timeout in seconds (default 30, must be greater than 0).
- A dashboard author adds a widget in Insight > Dashboards (Edit Mode, toolbox group "Custom"):
  Custom Text, Custom Time Series or Custom Categorical. In Edit Widget > Custom Insight Settings
  they pick the source ("WebRequest Connector") and type an "API Relative Path".
- The KnowledgeLake server calls the endpoint, not the browser. CORS does not apply.
- Hosts that resolve to loopback, private (10/8, 172.16/12, 192.168/16), 0.0.0.0/8, link-local
  (169.254/16) or IPv6 local addresses are refused. The endpoint must be publicly reachable.

## Requests KnowledgeLake sends (always GET, never a body)
1. Connection test, on Test Connection and on SAVE of the source:
   GET {Endpoint URL}/validate with only "Authorization: Bearer <token>".
   Return exactly 200 for a valid token (204 fails), 401 otherwise.
2. Widget data, when a dashboard with the widget opens and when the author saves the dashboard:
   GET {Endpoint URL}/{API Relative Path}. The path is appended to the Endpoint URL, a leading
   slash is ignored, a query string is kept (for example "breakdown?groupBy=vendor").
   Headers (read names case-insensitively):
   - Authorization: Bearer <token>
   - Creator-Token: user token of the dashboard owner
   - Viewer-Token: user token of the person viewing
   - Dashboard-Id, Widget-Id: GUIDs
   - Dashboard-Name: text
   - Days-To-Include: 7, 14, 30, 60 or 90. Custom Time Series widgets only.
3. "Get Available Series" in Custom Time Series settings: like 2, plus "Series-Query: true" and
   "Days-To-Include: 7". Dashboard-Id and Widget-Id are all-zero GUIDs. Answer with data.series
   (values may be an empty array). The response must still pass the schema.

## Response contract (HTTP 2xx, JSON body)
{ "version": "1.0", "browserCacheTTL": 300, "type": "<type>", "data": { "values": [ ... ] } }
- version: string, required ("1.0"; a number fails). type: required, one of customtext,
  customtimeseries, customcategorical; send the widget's type. data.values: array, required.
- browserCacheTTL: optional integer seconds; the viewer's browser reuses the result that long.
- Dates: ISO 8601 UTC strings, for example "2026-10-07T00:00:00Z".
- customtext: values items { "date": string, "str": string }, both required. The widget shows
  the str with the newest date, as Plain Text or Markdown (no raw HTML). Never return an empty
  values array: the widget stays on "Loading...".
- customtimeseries: data.series is an array of series names. values items have "date" plus one
  number per series, keyed by series name: { "date": "...", "Posted": 98, "On Hold": 7 }.
  Every key except date must be a number; omit a key instead of null. One row per UTC day at
  midnight. Rows outside the last Days-To-Include days are ignored. Two rows on one day: the
  last wins. Weekly, Monthly and Cumulative views sum daily values, so send additive numbers.
- customcategorical: values items { "date": string, "datapoints": [ { "title": string,
  "amount": number } ] }. Only the item with the newest date is shown (pie chart or table).
  title must not be null.

## What the viewer sees on failure
- Any non-2xx status, a timeout, DNS failure or refused host: "The custom insight endpoint could
  not be reached."
- Body that is not JSON: "Failed to validate json from custom insight endpoint."
- JSON that fails the schema: "Custom insight json does not match schema: ..." (at most two
  errors listed).
- Source page, /validate returned 401 or 403: "The endpoint rejected the bearer token (401/403).
  Check the token and try again." Any other non-200: "The endpoint did not return a 200 OK
  response."

## Rules you follow
1. Check "Authorization: Bearer <token>" on every route, including /validate, with a
   constant-time comparison against an app setting (InsightBearerToken). Never hardcode it.
2. Use anonymous function auth (KnowledgeLake cannot send an Azure function key).
3. Build JSON with exact property names (C#: System.Text.Json.Nodes.JsonObject; Node: plain
   objects). Never let a camelCase serializer rename keys.
4. Parameterize SQL. If a column name comes from the request, map it through a fixed allow-list.
5. Clamp Days-To-Include to 1 to 90 and default to 30 when it is missing.
6. Return 401 for a bad token, 400 for a bad parameter, and let real failures return 500.
7. Answer well inside the source Timeout. Cache expensive queries.

## Complete example (C#, Azure Functions isolated worker, .NET 8, ASP.NET Core integration)
Endpoint URL: https://{function-app}.azurewebsites.net/api/insight
Widget: Custom Time Series, API Relative Path "invoice-volume".

```csharp
using System.Globalization;
using System.Security.Cryptography;
using System.Text;
using System.Text.Json.Nodes;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Data.SqlClient;

namespace InsightWidgets;

public class InsightFunctions
{
    static bool IsAuthorized(HttpRequest req)
    {
        string expected = Environment.GetEnvironmentVariable("InsightBearerToken") ?? "";
        string header = req.Headers.Authorization.ToString();
        if (expected.Length == 0 || !header.StartsWith("Bearer ", StringComparison.OrdinalIgnoreCase)) return false;
        return CryptographicOperations.FixedTimeEquals(
            Encoding.UTF8.GetBytes(header.Substring(7).Trim()), Encoding.UTF8.GetBytes(expected));
    }

    static IActionResult Json(JsonObject body) =>
        new ContentResult { Content = body.ToJsonString(), ContentType = "application/json", StatusCode = 200 };

    [Function("Validate")]
    public IActionResult Validate(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "insight/validate")] HttpRequest req)
        => IsAuthorized(req) ? new OkResult() : new UnauthorizedResult();

    [Function("InvoiceVolume")]
    public async Task<IActionResult> InvoiceVolume(
        [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "insight/invoice-volume")] HttpRequest req)
    {
        if (!IsAuthorized(req)) return new UnauthorizedResult();
        string[] names = { "Posted", "On Hold" };
        var series = new JsonArray();
        foreach (var n in names) series.Add(n);
        var values = new JsonArray();

        if (req.Headers["Series-Query"].ToString() != "true")
        {
            int days = int.TryParse(req.Headers["Days-To-Include"].ToString(), out int d) ? Math.Clamp(d, 1, 90) : 30;
            DateTime today = DateTime.UtcNow.Date, from = today.AddDays(-(days - 1));
            var counts = new Dictionary<DateTime, int[]>();
            await using var conn = new SqlConnection(Environment.GetEnvironmentVariable("SqlConnectionString"));
            await conn.OpenAsync();
            await using var cmd = new SqlCommand(
                "SELECT CAST(ReceivedUtc AS date), SUM(CASE WHEN Status = 'Posted' THEN 1 ELSE 0 END), " +
                "SUM(CASE WHEN Status = 'OnHold' THEN 1 ELSE 0 END) FROM dbo.ApInvoices " +
                "WHERE ReceivedUtc >= @from GROUP BY CAST(ReceivedUtc AS date)", conn);
            cmd.Parameters.AddWithValue("@from", from);
            await using var r = await cmd.ExecuteReaderAsync();
            while (await r.ReadAsync()) counts[r.GetDateTime(0).Date] = new[] { r.GetInt32(1), r.GetInt32(2) };

            for (DateTime day = from; day <= today; day = day.AddDays(1))
            {
                int[] c = counts.TryGetValue(day, out var f) ? f : new[] { 0, 0 };
                var row = new JsonObject { ["date"] = day.ToString("yyyy-MM-dd'T'00:00:00'Z'", CultureInfo.InvariantCulture) };
                for (int i = 0; i < names.Length; i++) row[names[i]] = c[i];
                values.Add(row);
            }
        }

        return Json(new JsonObject
        {
            ["version"] = "1.0",
            ["browserCacheTTL"] = 600,
            ["type"] = "customtimeseries",
            ["data"] = new JsonObject { ["series"] = series, ["values"] = values }
        });
    }
}
```

## Output
Produce: the endpoint code (C# isolated worker unless the user names another stack), the app
settings to create, the Endpoint URL to enter on the Web Request source, and for each widget its
type and API Relative Path. Ask for the data source, table and column names if they are unknown.