kennraDocs

Quickstart

This guide takes you from no token to your first write in under five minutes: create a developer token, install the SDK, register a company and read its brief. Then it shows what a proposal looks like and how to verify a webhook.

Every example comes in TypeScript with @kennra/sdk, curl, MCP and the kennra CLI. Pick a tab, and the other examples follow your pick.

1. Create a developer token

In the admin at https://app.kennra.com, open Settings → Tokens and select Create token. Give it a name, keep Read and write customer data, and copy the token. Kennra keeps only a fingerprint and can't show it again. A token lasts at most 90 days.

The token acts for you and never gets more access than you have. In a test, development or demo workspace, such as your sandbox, its writes apply at once. In staging and production each write becomes a proposal that you approve (step 5).

You can also create the token with the CLI:

kennra tokens create --name "Quickstart"

Keep the token in an environment variable. The SDK, the CLI and the curl examples read it from there:

export KENNRA_TOKEN='<your developer token>'

2. Install the SDK

bun add @kennra/sdk

With npm: npm install @kennra/sdk.

The SDK has no dependencies and runs wherever fetch and Web Crypto do: Node 18 and later, Bun, Deno, browsers and edge runtimes. It reads KENNRA_TOKEN and KENNRA_API_URL (default https://api.kennra.com):

import { Kennra } from '@kennra/sdk';
 
const kennra = new Kennra(); // or new Kennra({ token: '…' })

With curl you need nothing to install. You call each operation by its name: { "operationName": "RegisterOrganization", "variables": { … } }. The API runs the persisted operation of that name, with the same allowlist, purposes and limits as every other client. GET https://api.kennra.com/graphql/operations lists the names.

3. Register a company

Writes are semantic commands. Each takes an idempotency key: send the same key again and you get the same company back, with idempotentReplay: true, instead of a second one. The SDK makes a key per call and keeps it across retries; pass your own to make a script safe to run twice.

const company = await kennra.organizations.register(
  { legalName: 'Nordlys Utstyr AS' },
  { idempotencyKey: 'quickstart-nordlys-1' },
);
if (company.status === 'proposed') throw new Error('See step 5');
 
console.log(company.partyId);

The result is a union. With curl, check __typename before you read the fields:

{
  "data": {
    "registerOrganization": {
      "__typename": "RegisterOrganizationSuccess",
      "partyId": "01jd3k9q7xw2m8c4v6t5hpa1rz",
      "consistencyToken": "48121",
      "idempotentReplay": false
    }
  },
  "extensions": {
    "kennra": { "auditId": "…", "requestId": "…", "purpose": "organization.management", "withheld": [] }
  }
}

The SDK turns the union into status: 'applied' or status: 'proposed', and throws a KennraError for the error members. IdentityConflict means Kennra found a likely duplicate and created nothing; ValidationFailed lists problems per field. See Errors below.

The MCP tab needs the client connected first: see MCP for the one-step connection. The CLI signs in with a developer token (kennra login --token-stdin), or reads KENNRA_TOKEN.

4. Read the brief

OrganizationBrief returns the company with its traits and open deals. Kennra builds its read models from events, shortly after the write. The SDK sends the consistency token of your last write, so the read waits until it sees the company, for at most 3 seconds. With curl, send it yourself as kennra-consistency-token.

const brief = await kennra.organizations.brief(company.partyId);
 
console.log(brief?.legalName, brief?.deals.nodes); // null if you may not see it
{
  "data": {
    "organization": {
      "id": "01jd3k9q7xw2m8c4v6t5hpa1rz",
      "legalName": "Nordlys Utstyr AS",
      "orgNumber": null,
      "traits": [],
      "deals": { "nodes": [] }
    }
  }
}

Fields that your purpose or PII level doesn't cover come back as null and are listed in extensions.kennra.withheld with a reason. See Concepts.

5. Handle a proposal

In staging and production, your token's writes are proposals by default: Kennra saves the command, and you approve it before it runs. The write then returns ProposalCreated with a proposalId and the approver, not an error.

const company = await kennra.organizations.register({ legalName: 'Nordlys Utstyr AS' });
 
if (company.status === 'proposed') {
  console.log(`${company.approver} approves proposal ${company.proposalId} in Kennra`);
} else {
  console.log(await kennra.organizations.brief(company.partyId));
}

You approve a proposal in the admin under For you, or with the CLI signed in as yourself. Approving runs the command with you as approver, and the audit log shows both. A token never approves its own proposals. To let it write directly in production, change its write modes on the agent page under Agents.

6. Verify a webhook

Kennra sends events to apps, signed per Standard Webhooks. Verify every request with your signing secret before you trust it. Pass the raw body: a body parsed and serialized again no longer matches.

import { verifyWebhook, WebhookVerificationError } from '@kennra/sdk';
 
export default {
  async fetch(req: Request): Promise<Response> {
    try {
      const event = await verifyWebhook<{ id: string; type: string }>(req, process.env.KENNRA_WEBHOOK_SECRET!);
      console.log(event.type); // deduplicate on the webhook-id header, then queue the work
      return new Response(null, { status: 204 });
    } catch (e) {
      if (e instanceof WebhookVerificationError) return new Response(e.code, { status: 401 });
      throw e;
    }
  },
};

verifyWebhook rejects a timestamp more than 5 minutes off and takes a list of secrets during a rotation. Your app reads its signing secrets from GET /apps/installation. See Webhooks for the request, retries and replay.

Errors

Every answer carries extensions.kennra.requestId, and every error carries extensions.requestId. Quote it when you ask for help. If you can see the request log, the error also has extensions.requestUrl, a link to the request in the admin.

The SDK throws a KennraError with the same fields:

import { KennraError } from '@kennra/sdk';
 
try {
  await kennra.organizations.register({ legalName: '' });
} catch (e) {
  if (!(e instanceof KennraError)) throw e;
  console.error(e.code, e.message); // VALIDATION_FAILED …
  for (const p of e.problems) console.error(p.path, p.message);
  console.error(e.requestId, e.next);
}

The SDK retries 429, 5xx, RATE_LIMITED and network errors with backoff, and keeps the idempotency key, so a retry never writes twice.

Next steps

  • Learn the model in Concepts.
  • Read about errors, pagination and limits in GraphQL API.
  • Connect Claude or another agent with MCP.
  • Build an integration as an app.