Skip to content
OrbContext
22 pages

Guide

Knowledge authoring

Write, publish and unpublish a bot’s knowledge from your CMS or help centre.

The knowledge authoring API lets your own system write the bot's knowledge. Use it to keep FAQs, policies or product notes in step with a CMS, a help centre or a spreadsheet you already maintain. It writes the same entries as the knowledge editor in the dashboard, so your team sees everything the API wrote, and the API sees everything your team wrote.

An entry is plain text, Markdown or a question and answer. Saving it creates a draft, which the bot cannot answer from. Publishing a saved revision makes it answer. While a changed version is indexed, the previous one keeps answering, so there is no gap.

Create the keys

In the dashboard, open API & Keys, choose One bot, and pick the permissions. Authoring keys always belong to a single bot. A workspace-wide key cannot have them.

ScopeAllows
knowledge:draftsList, read, create and save the bot’s entries.
knowledge:publishPublish a saved revision, or unpublish an entry.

Keep them separate if you can. A service that only prepares drafts never needs to change what the bot says, and a reviewer's tool can publish without being able to edit.

Write and publish an entry

  1. Create a draft

    Send an Idempotency-Key with every create. Use an identifier from your own system, such as the CMS article ID, so a retry after a timeout returns the same entry instead of a second one.

    Shell
    curl "$ORBCONTEXT_API_URL/v1/bots/$BOT_ID/knowledge/entries" \
      -H "Authorization: Bearer $DRAFTS_KEY" \
      -H 'Content-Type: application/json' \
      -H 'Idempotency-Key: cms-article-1042' \
      -d '{"format":"qa","question":"When can I collect my order?","answer":"Weekdays from 9 AM to 5 PM."}'

    You should see: 201 with an id, revision: 1 and status: "draft".

  2. Save changes

    Send the revision you last read. If someone saved since, you get 409 and nothing is overwritten: read the entry again and apply your change to it.

    Shell
    curl -X PATCH "$ORBCONTEXT_API_URL/v1/knowledge/entries/$ENTRY_ID" \
      -H "Authorization: Bearer $DRAFTS_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"revision":1,"draft":{"format":"qa","question":"When can I collect my order?","answer":"Weekdays from 10 AM to 5 PM."}}'
  3. Publish a revision

    Name the revision to publish. You get 202 while it is indexed.

    Shell
    curl "$ORBCONTEXT_API_URL/v1/knowledge/entries/$ENTRY_ID/publish" \
      -H "Authorization: Bearer $PUBLISH_KEY" \
      -H 'Content-Type: application/json' \
      -d '{"revision":2}'
  4. Wait until it is live

    Poll the summary with the drafts key until publishedRevision equals the revision you published and status is published. If it says failed, error says why, and the previous version keeps answering.

    Shell
    curl "$ORBCONTEXT_API_URL/v1/knowledge/entries/$ENTRY_ID?view=summary" \
      -H "Authorization: Bearer $DRAFTS_KEY"

Take an entry out of answers

Unpublishing removes the entry from answers at once and keeps its draft, so you can publish it again later. Use it when the source is withdrawn, or to roll back a bad publish.

Shell
curl -X POST "$ORBCONTEXT_API_URL/v1/knowledge/entries/$ENTRY_ID/unpublish" \
  -H "Authorization: Bearer $PUBLISH_KEY"

Deleting entries and managing FAQ collections are done in the dashboard.

What an entry holds

FieldNotes
formattxt, md or qa. It cannot be changed after the entry is created.
title, bodytxt and md. The title is 1 to 120 characters, the body up to 200 KB.
question, answerqa. The question is up to 300 characters, the answer up to 4,000.
variantsqa. Up to 10 other ways of asking the question.
collectionId, orderqa. The FAQ collection it belongs to, and its place in it.
scopeOptional: audience, location, effectiveFrom and effectiveUntil, which work like a document’s.

Statuses

StatusMeaning
draftSaved, and not answering. A new or unpublished entry.
publishingA revision is being indexed. The previous version, if any, still answers.
publishedThe latest saved revision is answering.
unpublishedAn older revision is answering, and newer changes are saved but not yet published.
failedThe last publish failed. error says why.

Example: sync articles from your CMS

sync.ts
const API = process.env.ORBCONTEXT_API_URL!; // https://api-staging.orbcontext.com while testing
const BOT = process.env.ORBCONTEXT_BOT_ID!;
const drafts = { Authorization: `Bearer ${process.env.ORBCONTEXT_DRAFTS_KEY}` };
const publish = { Authorization: `Bearer ${process.env.ORBCONTEXT_PUBLISH_KEY}` };
const json = { 'Content-Type': 'application/json' };

async function syncArticle(article: { id: string; entryId?: string; title: string; body: string }) {
  const draft = { format: 'md', title: article.title, body: article.body };
  let entry;
  if (!article.entryId) {
    const res = await fetch(`${API}/v1/bots/${BOT}/knowledge/entries`, {
      method: 'POST',
      headers: { ...drafts, ...json, 'Idempotency-Key': `cms-${article.id}` },
      body: JSON.stringify(draft),
    });
    entry = await res.json();
  } else {
    const current = await (await fetch(`${API}/v1/knowledge/entries/${article.entryId}`, { headers: drafts })).json();
    const res = await fetch(`${API}/v1/knowledge/entries/${article.entryId}`, {
      method: 'PATCH',
      headers: { ...drafts, ...json },
      body: JSON.stringify({ revision: current.revision, draft }),
    });
    if (res.status === 409) throw new Error('Changed in the dashboard meanwhile; sync again.');
    entry = await res.json();
  }
  await fetch(`${API}/v1/knowledge/entries/${entry.id}/publish`, {
    method: 'POST',
    headers: { ...publish, ...json },
    body: JSON.stringify({ revision: entry.revision }),
  });
  return entry.id; // store it with the article for the next sync
}

With the JavaScript SDK

@orbcontext/sdk 0.2.0 and later wraps these routes as orb.knowledge.entries. See the SDK page.

TypeScript
const entry = await orb.knowledge.entries.create(
  botId,
  { format: 'md', title: article.title, body: article.body },
  { idempotencyKey: `cms-${article.id}` },
);
await orb.knowledge.entries.publish(entry.id, { revision: entry.revision });
await orb.knowledge.entries.waitUntilPublished(entry.id, entry.revision);

Limits and retries

LimitDetail
Entries per bot500, counting both the dashboard and the API.
Draft storagePer workspace: 5 MB on Free, 25 MB on Starter, 100 MB on Pro and 500 MB on Enterprise. Past it, creating or growing a draft returns 403 draft_storage_full. Shrinking and deleting always work.
Published entriesCount against the plan’s documents per bot (text and Markdown) or Q&A answers per bot.
Publishing10 publish or unpublish requests a minute per workspace, across its keys.
CreditsPublishing is charged like an upload, about 0.05 credit per 500 words. Drafts are free, and publishing unchanged content again costs nothing.
  • Create is safe to retry with the same Idempotency-Key and the same draft. The same key with a different draft returns 409.
  • Save and publish are safe to retry with the same revision. A stale revision returns 409.
  • Without the plan feature, creating a key or using one returns 403 with plan_required. Keys stop working at once after a downgrade.

Every request is in the API reference, and you can try them in the playground.