kennraDocs

External fields

An external field is a trait field that points at one object in another system: a product variant in Crystallize, a machine in an asset register. The workspace keeps the relationship, such as "this company's machine is variant K200-400". The app that owns the object answers for it live.

This page has three parts: configure and use external fields in a workspace, provide object types from an app, and products and variants from Crystallize.

Configure an external field

An external field comes from an installed app that provides object types. In the admin, open a Kind's trait, add a field and pick the type Object in an app. Then pick the app, the object type and an optional Only from filter. The type is offered only while an installed app provides objects.

In a trait file, the field looks like this:

modell:
  primitive: external
  external: { app: crystallize, object: variant, scope: { folder: /maskiner } }
  piiClass: none
  description: The machine model, a product variant in the machines folder.
KeyMeaning
external.appThe app that provides the objects. It can't change once the field is published
external.objectOne object type, such as product or variant. A field points at one type, never at either. It can't change once published
external.scopeThe app's own filters, by key. Several values mean any of them. It can change in a later version

A field holds no personal data and is not indexed: segments read its snapshot. A published field keeps working when its app is uninstalled. Values keep their last snapshot.

Definition errors:

CodeCause
UNKNOWN_EXTERNAL_OBJECTNo installed app provides the object type
EXTERNAL_CONFIG_REQUIREDprimitive: external without external
UNKNOWN_SCOPE_FILTERA scope key the object type doesn't declare
EXTERNAL_NOT_PERSONALpiiClass is anything other than none
IDENTIFIER_CHANGEDapp or object changed after publishing. Make a new field and migrate

Scope

The scope keeps a field to the objects that fit it, such as machines and not spare parts. Each filter is either a prefix (folder: /maskiner takes the folder and everything under it) or equals (shape: maskin). The picker searches only inside the scope. Kennra also checks every write against the object's own snapshot, so an app can't widen it: an object outside the scope fails with TARGET_OUT_OF_SCOPE.

When you change the scope, current values outside it stay. Kennra marks them Outside the filter (ExternalLink.inScope: false).

Set a value

Set the object's id with setTraitValues. Kennra asks the app for the object before it writes, and stores the answer as a snapshot.

{
  "operationName": "SetTraitValues",
  "variables": {
    "idempotencyKey": "machine-8812-model",
    "input": {
      "entityId": "rec_01jd…",
      "trait": "custom.maskin_modell",
      "values": [{ "field": "modell", "value": { "external": "KOMP-K200-400" }, "validFrom": "2025-03-01T00:00:00Z" }]
    }
  }
}
ErrorMeaningNext step
EXTERNAL_NOT_FOUNDThe app has no object with that idSearch for the object again and use its id
EXTERNAL_UNAVAILABLEThe app did not answer. Nothing was storedTry again
TARGET_OUT_OF_SCOPEThe object is outside the field's scopePick an object inside the scope, or change the scope

With MCP, set_trait_values and create_record take the object's id. With the CLI, kennra traits plan reports a scope change as an update and an app or object change as an error.

History

A value is a link with time, like a reference field. A new object ends the current link where the new one starts, so a machine that changed model keeps its earlier model by name, under Earlier (n). Setting the same object again keeps the link and its start. With retract and validTo you end a link without a new one.

Read the links with externalLinks(entityId, trait, field, includeEnded, asOf).

Snapshots and "No longer exists"

Kennra keeps a snapshot of each value: the envelope (id, title, subtitle, imageUrl, url) and the typed fields the object type declares. It refreshes the snapshot in two ways:

  • When someone opens the value. The side panel asks the app live (externalObjects), and Kennra writes a changed answer back in the background.
  • Every hour. Kennra asks the app for a page of each workspace's values and writes back what changed. An unchanged snapshot writes nothing.

When the app says an object no longer exists, Kennra keeps the value and marks it No longer exists (gone, goneAt). It never drops the value. If the object comes back, the next refresh clears the mark.

When the app doesn't answer, Kennra shows its own copy with the date. When the app answers that it can't read the objects with its current settings, the picker says so. Ask an admin to check the app's settings under Apps.

Segments by path

A trait condition on an external field takes path into the snapshot:

pathCompares
id (default)The object's id
title, subtitleThe envelope's text
goneAtWhen the object stopped existing at the source
fields.<key>A typed field, as its declared type. money is Money ("NOK 19990.00") and compares within its currency, textList with containsAny and containsAll
fields.<key>.<name>One attribute of an attributes field

Machines of one product:

{ "type": "trait", "trait": "custom.maskin_modell", "field": "modell", "path": "fields.productId", "op": "eq", "value": "6650a1c0e4b0000000000101" }

Companies with such a machine:

{ "type": "hasRecord", "kind": "custom.maskin", "where": { "type": "trait", "trait": "custom.maskin_modell", "field": "modell", "path": "fields.productId", "op": "eq", "value": "6650a1c0e4b0000000000101" } }

SegmentCatalog.fields lists one entry per path, with path and pathLabel.

GraphQL

OperationWhat it does
ExternalObjectTypesThe object types of the installed apps, with their fields and scope filters
ExternalObjectSearchThe picker: objects that match text inside the field's scope, at most 20, best first. Live, cost 200
ExternalObjectsThe objects live through the app, for a record's field or by ids. Live, cost 200. missing lists ids that no longer exist
ExternalLinksThe links with their history

A live answer has live (LIVE, CACHED or UNAVAILABLE) and a reason, as described in Live lookups.

Provide object types from an app

An app declares its object types in capabilities.objects and answers two lookups: object.search for the picker, and object.resolve for writes, the live panel and the refresh.

capabilities:
  objects:
    - type: variant
      contract: shop.variant@1             # <app id>.<type>@<n>; a change of meaning is a new contract
      label: { en: Product variant, nb: Produktvariant }
      fields:                              # typed snapshot fields Kennra keeps next to the envelope
        - { key: sku, type: text, label: { en: SKU, nb: SKU } }
        - { key: productId, type: text, label: { en: Product ID, nb: Produkt-ID } }
        - { key: price, type: money, label: { en: Price, nb: Pris } }
        - { key: attributes, type: attributes, label: { en: Attributes, nb: Egenskaper } }
        - { key: folderPath, type: text, label: { en: Folder, nb: Mappe } }
      scope:                               # the filters a field may set
        - { key: folder, label: { en: Folder, nb: Mappe }, field: folderPath, match: prefix }
  lookups:
    - { object: object.search, refPattern: "*", url: /lookup/object-search, timeoutMs: 1000, purposes: [organization.management, sales.b2b] }
    - { object: object.resolve, refPattern: "*", url: /lookup/object-resolve, timeoutMs: 1000, purposes: [organization.management, sales.b2b] }
  ui:
    domains: [media.shop.example]          # where images and links may point
KeyRule
typeUnique in the app
contractStarts with the app id (CONTRACT_NOT_OWNED)
label{ en, nb }
fields[]key, type and label. Types are text, number, boolean, date, money, textList and attributes. A key is never an envelope key (id, title, subtitle, imageUrl, url)
scope[]key, label, the field it reads (a text or textList field) and match (equals or prefix)

Object types need both lookups (OBJECTS_WITHOUT_LOOKUPS). Both go through the lookup broker: signed, checked against their shape, cached per cacheTtlSeconds, with a timeout, a circuit breaker and fail-open. Kennra asks the installation of the app the field names, never another app with the same object type.

object.search

The request's query is { type, text, scope, limit }, with limit at most 20. An empty text asks for the first objects in the scope. The ref is <type>:<scope>:<limit>:<text>, for the cache.

{
  "type": "lookup",
  "object": "object.search",
  "ref": "variant:folder=/maskiner:10:k200",
  "query": { "type": "variant", "text": "k200", "scope": { "folder": "/maskiner" }, "limit": 10 },
  "installationId": "01jd5x2n8q4r7t9v3w6y1z0abc",
  "workspace": "fjellsport-demo",
  "purposeClass": "organization.management",
  "requestedBy": { "type": "user", "pseudonym": "u_7f3a…" },
  "deadline": "2026-11-27T14:02:01.000Z"
}

Answer with at most limit objects inside the scope, best match first:

{ "data": { "results": [ { "id": "KOMP-K200-400", "title": "Kompressor K200 (3 kW, 400 V)", "subtitle": "KOMP-K200-400", "fields": { "sku": "KOMP-K200-400", "folderPath": "/maskiner" } } ] }, "fetchedAt": "2026-11-27T14:02:00.410Z" }

Kennra checks the scope again on each result and drops what is outside it.

object.resolve

The request's query is { type, ids }, with at most 50 ids. The ref is <type>:<sorted ids>. Answer with the objects that exist:

{ "data": { "objects": [ { "id": "KOMP-K200-400", "title": "Kompressor K200 (3 kW, 400 V)", "fields": { "sku": "KOMP-K200-400", "price": "NOK 19990.00" } } ] } }

An id you leave out no longer exists at the source. Kennra keeps the value and marks it No longer exists. Answer 404 only for a query you don't answer at all, such as an unknown type, and 403 when your settings don't let you read the source.

The ExternalObject envelope

FieldRule
idYour stable id for the object. Kennra stores it in the value
titleRequired. The name people see
subtitleOptional, such as a SKU or a folder
imageUrlOptional. https on a host in ui.domains, or a data:image/… URL
urlOptional. The object in your own UI, https on a declared host. Kennra shows it as Open in your app
fieldsThe typed fields your object type declares. Kennra drops anything else
relatedLive only, never stored: { type, items: [{ id, title, subtitle?, imageUrl? }] }, such as a product's variants

Send product data, never personal data.

Signed images

Kennra never hands your image URL to a browser. It stores the source URL in the snapshot and serves a signed link through its own media proxy, valid for 15 minutes. The proxy fetches only https URLs on your ui.domains, or a data:image/… URL. If your images need a token, return your own short-lived signed URL on your host instead.

With the App SDK

import type { ExternalObjectResolveResult, ExternalObjectSearchResult } from '@kennra/app-sdk/protocol';
 
// app is the createApp(…) from your app's entry point; shop is your own client of the source.
 
app.lookup('object.search', async ({ req, ctx }) => {
  const { type, text, scope, limit } = req.query as { type: string; text: string; scope: Record<string, string | string[]>; limit: number };
  if (type !== 'variant') return { notFound: true };
  const hits = await shop.searchVariants(text, scope, limit, String(ctx.secrets['apiToken']));
  const data: ExternalObjectSearchResult = { results: hits.map(toObject) };
  return { data };
});
 
app.lookup('object.resolve', async ({ req, ctx }) => {
  const { type, ids } = req.query as { type: string; ids: string[] };
  if (type !== 'variant') return { notFound: true };
  const found = await shop.variantsBySku(ids, String(ctx.secrets['apiToken']));
  const data: ExternalObjectResolveResult = { objects: found.map(toObject) };
  return { data };
});

toObject maps your record to the envelope and the declared fields.

Products and variants from Crystallize

The Crystallize app provides two object types:

TypeContractIdFields
productcrystallize.product@1The item idshape, folderPath, brand (when the shape has a brand component), skus, variantCount
variantcrystallize.variant@1The SKUsku, productId, productName, price (the default price variant), attributes, stock (summed over the stock locations), shape, folderPath

A variant's id is its SKU. Crystallize variants have no id of their own, and orders carry the SKU. A product's live answer lists its variants under related.

Both types take two filters:

FilterMatchExample
folderPrefix of the folder path/maskiner takes /maskiner/kompressor-k200 and everything else under it
shapeThe shape identifiermaskin

How the app reads the catalogue

The app reads everything through Crystallize's Discovery API, at https://api.crystallize.com/<tenant>/discovery. It doesn't use the Search API, which Crystallize is deprecating.

  • Search queries each product shape in the field's shape filter, or every product shape in the tenant, in one request. The app finds the product shapes in the tenant's schema and keeps the list for ten minutes. It merges the answers, best match first, and finds names and SKUs from their first letters.
  • Resolve looks products up by item id and variants by SKU, across every shape.
  • Images come from media.crystallize.com only. Kennra serves them as signed links.

The static token

The Discovery API is open unless you protect it. If you protect it under Settings → API Access in Crystallize ("Basic authentication"), it accepts only a static token, never an access token. Paste that token in the app's setting Discovery API static token. The access token ID and secret stay for customers, orders and webhooks.

Without the token, a protected tenant still syncs customers and orders. The picker says the app can't read products with its current settings, and values keep their last snapshot. Test connection shows the state on the line Products and variants:

ValueNext step
ReadableNothing to do
Protected: add the static tokenCopy the static token from Settings → API Access in Crystallize, paste it and save
The static token was not acceptedCopy the token again, paste it and test again
The catalogue language is not one of the tenant'sSet Catalogue language to one of the tenant's languages, such as en