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.
| Scope | Allows |
|---|---|
knowledge:drafts | List, read, create and save the bot’s entries. |
knowledge:publish | Publish 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
Create a draft
Send an
Idempotency-Keywith 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:
201with anid,revision: 1andstatus: "draft".Save changes
Send the revision you last read. If someone saved since, you get
409and 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."}}'Publish a revision
Name the revision to publish. You get
202while 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}'Wait until it is live
Poll the summary with the drafts key until
publishedRevisionequals the revision you published andstatusispublished. If it saysfailed,errorsays 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.
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
| Field | Notes |
|---|---|
format | txt, md or qa. It cannot be changed after the entry is created. |
title, body | txt and md. The title is 1 to 120 characters, the body up to 200 KB. |
question, answer | qa. The question is up to 300 characters, the answer up to 4,000. |
variants | qa. Up to 10 other ways of asking the question. |
collectionId, order | qa. The FAQ collection it belongs to, and its place in it. |
scope | Optional: audience, location, effectiveFrom and effectiveUntil, which work like a document’s. |
Statuses
| Status | Meaning |
|---|---|
draft | Saved, and not answering. A new or unpublished entry. |
publishing | A revision is being indexed. The previous version, if any, still answers. |
published | The latest saved revision is answering. |
unpublished | An older revision is answering, and newer changes are saved but not yet published. |
failed | The last publish failed. error says why. |
Example: sync articles from your CMS
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.
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
| Limit | Detail |
|---|---|
Entries per bot | 500, counting both the dashboard and the API. |
Draft storage | Per 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 entries | Count against the plan’s documents per bot (text and Markdown) or Q&A answers per bot. |
Publishing | 10 publish or unpublish requests a minute per workspace, across its keys. |
Credits | Publishing 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-Keyand the same draft. The same key with a different draft returns409. - 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
403withplan_required. Keys stop working at once after a downgrade.
Every request is in the API reference, and you can try them in the playground.