REST API Knowledge - edmozley/freeitsm GitHub Wiki

๐Ÿ“š REST API: Knowledge

The complete usage guide for the Knowledge Base module of the REST API โ€” every URL, method, parameter and response shape. Mirrors the interactive documentation at System โ†’ API โ†’ Documentation (with its live "Try it" tester).

Note

New to the API? The basics table on REST API: Tickets covers base URL, authentication, the response envelope, error codes, rate limits and PATCH semantics โ€” identical across all modules.

What's distinctive about Knowledge:

๐Ÿข Shared or one company's An article has a company - null means shared with every company. A key scoped to some companies sees the shared articles and those companies' own; a key scoped to none sees only the shared ones (matches the UI).
๐Ÿท๏ธ Tags, not categories The module's only taxonomy is free-text tags โ€” send them as an array of names and they're created on the fly.
โ™ป๏ธ Recycle bin, not trash-forever DELETE archives; articles restore from the bin; permanent deletion only works from the bin and the bin auto-purges on the module's retention setting โ€” all exactly like the UI.
๐Ÿง  Embeddings stay warm If the module's OpenAI key is configured, creating or updating an article via the API regenerates its search embedding (best-effort, like the UI) โ€” so the AI chat and vector search find API-written articles too.
๐Ÿ‘€ View counts are opt-in Reading an article via the API does not bump view_count unless you pass ?count_view=true โ€” a deliberate divergence so sync jobs and chatbots don't inflate the stats the review screens use.

Warning

Article bodies are TinyMCE-style HTML stored verbatim โ€” the product performs no server-side sanitisation (the UI behaves identically). Only send trusted HTML, and sanitise on render if you display articles outside FreeITSM.


๐Ÿš€ Quick start

Sync a runbook from your docs pipeline into the KB:

B="https://your-server/api/v1"; K="Authorization: Bearer fitsm_โ€ฆ"

curl -X POST "$B/knowledge/articles" -H "$K" -H "Content-Type: application/json" -d '{
  "title": "How to reset your VPN token",
  "body_html": "<h2>Steps</h2><ol><li>Open the portal</li><li>Click reset</li></ol>",
  "tags": ["vpn", "how-to"],
  "next_review_date": "2026-12-01"
}'

Published immediately, tagged, embedded for AI search, and on the review calendar. ๐Ÿ“–


๐Ÿ“š Articles

๐ŸŸข GET /knowledge/articles โ€” list / search   ๐Ÿ”‘ knowledge.read

Published articles (or the recycle bin with archived=true). Each list item carries a 300-character plain-text preview instead of the full body. It is plain text with HTML entities decoded (&auml; arrives as รค, &lt; as <), words kept apart where tags were, and an ellipsis when it was cut - so escape it if you show it in a web page (PR #255).

Parameter Description
q ๐Ÿ” Keyword search across title and body (the module's own search โ€” no AI required)
tag Only articles carrying this tag (exact name)
author_id / owner_id Filter by author or owning analyst
review overdue ยท upcoming (next 30 days) ยท none โ€” the review screen's exact windows
modified_since ISO 8601 โ€” the sync-job filter
archived true lists the recycle bin (and runs the same retention auto-purge the UI runs on opening it)
sort modified_at (default, desc), created_at, title, view_count, next_review_date, id โ€” prefix - for descending
page / per_page Pagination โ€” default 1 / 25, max 100

๐Ÿ”ต POST /knowledge/articles โ€” create   ๐Ÿ”‘ knowledge.create

Articles are created published immediately unless you send "is_published": false, which saves a draft only analysts can see until somebody clicks Publish (or you PATCH is_published: true). Returns 201 with the full article.

The migration fields - folder_id, tenant_id, audience, is_published, access, processing, required_image_ids, client_reference - are described in Migrating a knowledge base in.

Field Required Description
title โœ… Max 255 characters
body_html The article content (HTML)
tags Array of tag names โ€” created on the fly, e.g. ["vpn", "how-to"]
owner_id Owning analyst (drives the review cycle)
next_review_date YYYY-MM-DD

๐ŸŸข GET /knowledge/articles/{id} โ€” get one   ๐Ÿ”‘ knowledge.read

The full article with body_html, tags, version number and a has_embedding flag. Add ?count_view=true to count the read as a view (UI parity โ€” otherwise machine reads leave the stats alone).

{ "data": { "id": 26, "title": "How to reset your VPN token",
    "tags": ["how-to", "vpn"],
    "author": { "id": 1, "name": "Administrator" }, "owner": null,
    "version": 2, "view_count": 41, "next_review_date": "2026-12-01",
    "is_archived": false,
    "created_at": "2026-07-03T12:18:31Z", "modified_at": "2026-07-03T12:19:07Z",
    "body_html": "<h2>Steps</h2><ol>โ€ฆ</ol>", "has_embedding": true } }

๐ŸŸ  PATCH /knowledge/articles/{id} โ€” update   ๐Ÿ”‘ knowledge.update

Field Notes
title / body_html New content
tags Replaces the article's tag set
owner_id / next_review_date Review-cycle fields (null clears)
save_as_version true = snapshot the current content into the version history first, then bump the version number โ€” exactly the UI's "Save as new version"

The search embedding is refreshed automatically after every create/update (when the OpenAI key is configured). An archived article answers 409 โ€” restore it first.

๐Ÿ”ด DELETE /knowledge/articles/{id} โ€” move to the recycle bin   ๐Ÿ”‘ knowledge.delete

Soft-archives the article. It stays restorable until the module's retention window (knowledge_recycle_bin_days, default 30; 0 = keep forever) purges it.

๐Ÿ”ต POST /knowledge/articles/{id}/restore โ€” restore   ๐Ÿ”‘ knowledge.restore

Brings an archived article back, exactly as it was.

๐Ÿ”ด DELETE /knowledge/articles/{id}/permanent โ€” permanently delete   ๐Ÿ”‘ knowledge.purge

Warning

Hard-deletes the article, its version history and its tag links (orphaned tags are cleaned up). Only allowed once the article is already in the recycle bin โ€” same guard as the UI. 409 otherwise.


๐Ÿ• Version history

Snapshots are only created when a save says so (save_as_version here, "Save as new version" in the UI) โ€” routine edits update in place.

๐ŸŸข GET /knowledge/articles/{id}/versions   ๐Ÿ”‘ knowledge_versions.read

The saved snapshots โ€” version number, title at the time, who saved it, when โ€” newest first.

๐ŸŸข GET /knowledge/articles/{id}/versions/{version}   ๐Ÿ”‘ knowledge_versions.read

One snapshot including its full body_html โ€” everything needed to diff or roll back (roll back by PATCHing the old body onto the article).


๐Ÿท๏ธ Tags

๐ŸŸข GET /knowledge/tags   ๐Ÿ”‘ reference.read

Every tag with its published-article count:

{ "data": [ { "id": 3, "name": "how-to", "article_count": 12 },
            { "id": 7, "name": "vpn", "article_count": 4 } ] }

๐Ÿšš Migrating a knowledge base in

(5.7.0 - PR #378 by @Dr4inder, #377.) Everything a script needs to recreate another knowledge base in FreeITSM: folders, access lists, pictures inside articles, and retries that never make duplicates. FreeITSM ships no connector for any particular product - you write the script that reads your old system; these are the endpoints it writes to.

The new permissions

Tick them on the key under System โ†’ API โ†’ Keys. They sit beside the existing knowledge permissions.

Permission Allows
knowledge_folders.read / .create Read the folder tree / create folders
knowledge_access.read / .manage Read / replace access lists. Also needs the key's analyst to be a Knowledge administrator
knowledge_images.read / .create / .delete Read / upload / delete pictures on an article
knowledge_imports.manage Send processing: "suppress" on an article save

The order that works

  1. Folders first, parents before children: POST /knowledge/folders with name, parent_id, client_reference.
  2. Each article as a draft, already in its folder and with its final company, audience and access list: POST /knowledge/articles with is_published: false, processing: "suppress", access, client_reference. The article is never briefly open: content and access are saved together.
  3. Its pictures: POST /knowledge/articles/{id}/images. Put each returned url into the HTML.
  4. Rewrite internal links using the ids you got back, then publish: PATCH /knowledge/articles/{id} with the new body_html, is_published: true, expected_revision and required_image_ids.

๐Ÿ” Safe to stop and run again: client_reference

Send your old system's id as client_reference on every create (folder, article, picture). It is remembered per analyst, operation and parent.

You send the same reference... You get
with the same content 200 and the object made the first time ("replayed": true) - nothing new is created
with different content 409 reference_conflict
after that object was deleted 404 - a retry never brings a deleted object back
while the first request is still running 409 reference_busy - send it again

So after a timeout, just send the same request again.

โœ‹ Do not overwrite a human's edit: expected_revision

Every article, folder and access list comes back with a revision. Send it back as expected_revision on a PATCH; if anybody changed the object since you read it, you get 409 revision_conflict and nothing is written. Read it again and decide.

๐Ÿ–ผ๏ธ Pictures

๐Ÿ”ต POST /knowledge/articles/{id}/images { "filename": "diagram.png", "content_base64": "โ€ฆ", "client_reference": "old-img-881" }. PNG, JPEG, GIF, WebP, BMP, HEIC/HEIF - no SVG - up to the install's limit (10 MiB unless an administrator chose otherwise). Returns id, sha256, size_bytes and url
๐ŸŸข GET /knowledge/images/constraints 5.9.0 (#417): the limit and formats in force - read these, never hard-code them. See below
๐ŸŸข GET /knowledge/articles/{id}/images The article's pictures
๐ŸŸข GET /knowledge/images/{id}/content The bytes, for your key
๐Ÿ”ด DELETE /knowledge/articles/{id}/images/{image_id} Remove one

๐Ÿ“ How big a picture may be (5.9.0, #417)

An administrator chooses the largest picture under Knowledge โ€บ Settings โ€บ Images: 5, 10, 20, 25 or 50 MiB. Nothing is typed in, and an upgrade keeps 10 MiB. Ask before you send:

GET /api/v1/knowledge/images/constraints
{ "data": {
    "max_bytes": 10485760,            // largest decoded image
    "default_max_bytes": 10485760,
    "max_base64_length": 13981016,    // longest content_base64 - base64 is about a third bigger
    "encoding": "base64",
    "formats": [ { "extension": "png", "mime_types": ["image/png"] }, "โ€ฆ" ],
    "request_max_bytes": 8388608,     // PHP post_max_size (null = none)
    "within_server_limits": false     // PHP's post_max_size or memory_limit is too small for max_bytes
} }

Over the limit you get 413 image_too_large, with the numbers in error.details - never anything about the picture itself:

{ "error": { "code": "image_too_large",
    "message": "The image is larger than this installation's limit of 10485760 bytes (10 MiB) decoded. โ€ฆ",
    "details": { "max_bytes": 10485760, "max_base64_length": 13981016 } } }

Warning

The server has its own limits, and FreeITSM never changes them. A picture of max_bytes travels as about 1.33 ร— that in base64, and PHP holds it in memory about five times over while it is checked and stored. So for the larger choices:

  • memory_limit must be at least about 5 ร— the image + 32 MB (PHP's 128 MB default covers 10 and 20 MiB).
  • post_max_size should be at least the request size. PHP still reads a JSON body above it, but warns on every one - and with display_errors on, that warning lands in front of the reply and spoils it.
  • A web server or proxy in front of PHP can refuse the request first with its own 413 - nginx's client_max_body_size defaults to 1 MB. FreeITSM cannot see this one. (The Docker image is Apache with post_max_size = 14M, which fits 10 MiB.)

The Images settings tab shows, for each choice, whether this server's PHP can take it and what to raise.

Each picture belongs to one article, and every read re-checks that article: its company, audience, access list, and whether it is published. A picture in a draft is seen only by analysts who can see the draft.

Important

The url works for signed-in analysts and portal users only. Nobody who is not signed in gets a picture, even from a public article - Ed, 19 November 2026: "you should not be able to view content of any sort if you are not authenticated in some way."

required_image_ids on the publishing PATCH lists the pictures the article must have; if one is missing, damaged or belongs to another article you get 422 missing_image and the article stays a draft.

๐Ÿ“„ Documents (5.12.0, #416)

The files and links in an article's Documents panel - the runbook PDF, the vendor's guide, a link into your DMS. Their own permissions: knowledge_documents.read, .create, .delete; downloading also needs documents.download.

๐ŸŸข GET /knowledge/articles/{id}/documents The article's documents. ?client_reference= finds the one a retry made
๐Ÿ”ต POST /knowledge/articles/{id}/documents Add one: a multipart file, an upload_id (a file sent in pieces, below), or external_url for a link. Optional title, description, show_in_help_centre (default false), client_reference, expected_revision
๐Ÿ”ต POST /knowledge/articles/{id}/documents/{document_id}/link Attach a document that is already somewhere else - on another article you can read. Already attached = 200, nothing changes
๐ŸŸ  PATCH /knowledge/articles/{id}/documents/{document_id} title, description, show_in_help_centre. A document attached anywhere else refuses a new title or description (409 document_shared) - they would change on every record that shows it; show_in_help_centre is per article and always allowed
๐Ÿ”ด DELETE /knowledge/articles/{id}/documents/{document_id} Detach it from this article. The same document stays on any other record it is on. ?expected_revision=
๐ŸŸข GET /knowledge/articles/{id}/documents/{document_id}/content The bytes, for your key, logged with the key and the size. A link answers with its external_url
  • Access is the article's, as your key sees it - company, audience, access list, published or draft. An article you cannot reach is 404, and so is a document that is not on that article, even if another article you can read has it.
  • A key limited to some companies can only attach a document it reaches through an article in those companies.
  • Retries are safe: the same client_reference with the same content returns the document as it is now (200, replayed: true) and writes nothing; different content is 409 reference_conflict; a document removed since is 404 and is not attached again.
  • The article's revision covers its documents - every change returns article_revision. Articles that already had documents before 5.12.0 get a new revision once, so an integration holding an old one sees one revision_conflict after the upgrade.
  • Archived articles take no new documents (409 archived).

๐Ÿ“ฆ Big files: send them in pieces (5.12.0)

A picture or a document can also go up in pieces, so a file of any size the install allows gets past PHP's upload_max_filesize (2 MB by default) and post_max_size (8 MB), and past a proxy's body limit - and a dropped connection carries on instead of starting again. The same idea as Microsoft Graph upload sessions or S3 multipart. Small files can still go in one request.

๐Ÿ”ต POST /uploads { "purpose": "knowledge_document", "filename": "runbook.pdf", "size": 31457280, "sha256": "โ€ฆ" } (sha256 optional). Size and type are checked now: 413 too_large, 422 invalid_type. Returns upload_id and chunk_bytes
๐ŸŸ  PUT /uploads/{upload_id}?offset=N The next piece, as raw bytes (application/octet-stream), at most chunk_bytes. A wrong offset is 409 offset_mismatch with received. Clients that can only POST: POST with X-HTTP-Method-Override: PUT
๐ŸŸข GET /uploads/{upload_id} How much arrived (received, size, complete) - to resume after a drop
๐Ÿ”ด DELETE /uploads/{upload_id} Give up
๐ŸŸข GET /uploads/limits chunk_bytes, how many unfinished uploads a key may have, expiry, and each purpose's max_bytes and formats

Then hand it over: POST /knowledge/articles/{id}/images or /documents with { "upload_id": "u_โ€ฆ" }. The type is checked again from the content itself (never SVG; a PHP file named .png is refused), and the limit in force then applies.

  • No new permission - an upload needs its purpose's create permission (knowledge_images.create or knowledge_documents.create); GET /uploads/limits needs either.
  • An upload is your key's - another key gets 404, even one acting as the same analyst.
  • A wrong sha256 at the last piece is 422 sha256_mismatch and the upload is discarded. Two pieces of the same upload at once: the second waits, or gets 409 upload_busy.
  • Unfinished uploads expire 24 hours after their last piece; finished ones not yet handed over count toward the key's limit until they do.
  • Not yet: project documents still take a multipart file only.

๐Ÿ”’ Access lists

GET / PATCH /knowledge/articles/{id}/access and /knowledge/folders/{id}/access:

{ "is_restricted": true, "inherits": false,
  "entries": [ { "principal_type": "team", "principal_id": 4 },
               { "principal_type": "analyst", "principal_id": 17 } ],
  "expected_revision": "โ€ฆ" }

principal_type is analyst, team, user (portal user) or user_group. A PATCH replaces the whole list. Every person or group you name must exist: 422 invalid_access otherwise, so map your old system's permissions first - FreeITSM never quietly drops an entry, because a dropped deny would widen access. The response also says the install's permission_model (containers or filing), which decides how folder rules are inherited - see Knowledge folders and permissions.

โš™๏ธ processing: "suppress"

A bulk import should not send thousands of articles to your AI provider or fire a workflow for each one. With processing: "suppress" (needs knowledge_imports.manage) the save skips the AI embedding and workflows; the search index is still updated. The response says what ran: "processing": { "search": "โ€ฆ", "ai": "suppressed", "workflows": "suppressed" }. Leave it off on the final publishing PATCH if you want the normal publish workflow to run.

Errors you will meet

HTTP error Means
409 reference_conflict That client_reference was used with different content
409 reference_busy The same reference is mid-write - retry
409 revision_conflict Changed since you read it
409 archived The article is in the recycle bin - restore it first
422 invalid_access Unknown principal type, or a person/group that does not exist
422 missing_image A required_image_ids picture is missing, damaged or on another article
422 invalid_image Not a supported picture, empty, or not valid base64
413 image_too_large Over the install's limit - error.details.max_bytes says what it is (5.9.0; before that, over 10 MiB was 422 invalid_image)
403 forbidden The key lacks the permission, the company, or the Knowledge administrator floor

How it works inside: Knowledge migration API - Developer Guide.


๐Ÿงช Worked example: docs-pipeline sync

A CI job that keeps the KB in step with a docs repo (knowledge: read, create, update + reference: read):

B="https://your-server/api/v1"; K="Authorization: Bearer fitsm_โ€ฆ"

# Upsert-by-title: find the article, PATCH it (with a version snapshot) or create it
ID=$(curl -s -H "$K" "$B/knowledge/articles?q=$(python3 -c 'import urllib.parse;print(urllib.parse.quote("How to reset your VPN token"))')" | jq -r '.data[0].id // empty')
if [ -n "$ID" ]; then
  curl -s -X PATCH "$B/knowledge/articles/$ID" -H "$K" -H "Content-Type: application/json" \
    -d "{\"body_html\": $(jq -Rs . < rendered.html), \"save_as_version\": true}"
else
  curl -s -X POST "$B/knowledge/articles" -H "$K" -H "Content-Type: application/json" \
    -d "{\"title\": \"How to reset your VPN token\", \"body_html\": $(jq -Rs . < rendered.html), \"tags\": [\"vpn\"]}"
fi

And the review-cycle report โ€” what's overdue for review, and who owns it?

curl -s -H "$K" "$B/knowledge/articles?review=overdue&sort=next_review_date&per_page=100" \
  | jq -r '.data[] | [.title, .next_review_date, (.owner.name // "unowned")] | @tsv'

Under the hood: REST API โ€” How It Works ยท Other modules: Tickets ยท Assets ยท Problems ยท Changes ยท Keys & permissions: System โ†’ API (System module) ยท Module docs: Knowledge.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ