knownprintDocs

SDKs

SDKs

The libraries for knownprint in the browser and on your server, what each one does, which are available today and which come with the SDK release.

knownprint has two halves, and so do its libraries. In the browser, a script identifies the visit and hands your page a request id. On your server, your backend reads the event behind that id with your secret key, verifies it and acts on it. Everything the server libraries do is a thin layer over the HTTP API, which you can call from any language today.

What is available

LibraryWhere it runsWhat it doesState
Browser agent /kp/agent.jsBrowserLoads from your own domain through your proxy and defines window.knownprint.Available
@knownprint/webBrowser, bundledThe same browser agent as an ES module, for applications that bundle their own JavaScript.Coming with the SDK release
@knownprint/sdk-jsBrowser, bundledA small layer over the agent that puts a fresh request id into your forms before each submit.Coming with the SDK release
@knownprint/sdk-nodeNode.js 22 or laterThe server API client, verifyRequestId with a shared store of used ids, and webhook verification.Coming with the SDK release
Go, Python and PHPYour serverServer libraries for the same API.Coming with the SDK release
HTTP APIAny serverEvery server operation: read and search events, attach account ids, feedback, visitors, deletion, webhooks, keys.Available

In the browser

The browser agent (available)

The script tag is the way to run knownprint in the browser today. It loads /kp/agent.js from your own site, which your proxy forwards to knownprint (Run knownprint from your domain), so the script and its identification requests are first party.

HTML
<script src="/kp/agent.js" defer></script>
JavaScript
// In a module script (<script type="module">), which runs after the deferred /kp/agent.js.
let requestId = null; // null: no request id, which your backend treats as unknown
try {
  if (window.knownprint) {
    const agent = await window.knownprint.load({ pk: 'pk_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' });
    ({ requestId } = await agent.identify());
  }
} catch {
  // The agent failed to load or to identify: go on without a request id.
}

window.knownprint is missing when a content blocker or a network error kept the script from loading, and load() rejects with load_failed when the agent itself cannot be fetched; in both cases your page goes on without a request id. The script defines window.knownprint with load and version. load takes the same options and returns the same Agent as @knownprint/web, so the reference on Web SDK covers both. Setup, options and consent are on Add the browser agent; sending the request id with your forms is on Protect your forms.

@knownprint/web and @knownprint/sdk-js (coming)

@knownprint/web is the agent as an ES module that imports nothing, for an application that bundles its own JavaScript and would rather not add a script tag. @knownprint/sdk-js builds on it (or on window.knownprint) and adds attach(form), which writes a fresh request id into a hidden kp_request_id field before each submit. Both are described on Web SDK.

On your server

The HTTP API (available)

Your backend needs three calls for the core flow, each with your secret key in Authorization: Bearer:

StepCallScope
Read the event behind a request idGET /v1/events/{request_id}events:read
Attach your account idPATCH /v1/events/{request_id}events:write
Delete a visitor on requestDELETE /v1/visitors/{visitor_id}visitors:delete
Shell
curl "$KNOWNPRINT_API/v1/events/$REQUEST_ID" \
  -H "Authorization: Bearer $KNOWNPRINT_SECRET_KEY"

The API address comes with your account; examples write it as $KNOWNPRINT_API. The full reference starts at API reference.

What a server SDK adds on top of these calls is small, and you can write it yourself in a few dozen lines:

  • Request id verification. Accept each request id once, within 10 seconds, only when the event was not replayed, comes from your origin and from the address that posted the form. Verify a request in your backend shows it in plain Node and in shell.
  • Webhook verification. Check the HMAC signature of each delivery and its timestamp. Verify webhooks has the algorithm and examples.
  • Typed errors. Every error is an application/problem+json body with a stable type (Errors).

Node SDK (coming)

@knownprint/sdk-node wraps the server routes, verifyRequestId with an in-memory or Redis store of used ids, and Knownprint.verifyWebhook. Its full reference is on Node SDK, so you can see what it will do and write code that is easy to move onto it.

Go, Python and PHP (coming)

Server libraries for Go, Python and PHP come with the SDK release. Until then, use the HTTP API from those languages: the verification is one GET, one atomic "set if absent" in your cache, and five comparisons, as Verify a request in your backend shows.

Versions and compatibility

  • The browser agent is served by your proxy from knownprint, so it updates without a deploy on your side. window.knownprint.version names the version a page runs.
  • The API is versioned in its path (/v1/). Parse answers leniently: read the fields you use and ignore any you do not know.
  • The event and webhook shapes the SDKs return are the same JSON the API answers, unchanged.