DM Champ Docs

Knowledge Base API

Your knowledge base is what the AI reads from. It has two parts, and this page covers both:

  • Knowledge sources (/kb-sources): the web pages and uploaded documents you feed the platform. Each one is read, split into sections, and turned into FAQs your AI can answer from.
  • Knowledge groups (/kb-groups): named bundles of FAQs you can apply to an Agent or a campaign in a single call, so knowledge you have already curated can be reused on the next Agent you create.

The FAQs a source produces land in the same library as the ones you write by hand, so once an import finishes you read, edit and link them with the FAQs API.

All endpoints are relative to https://api.dmchamp.com/v1 and need an API key: see API Access and Authentication. API access is a paid feature; without it, requests are rejected with a 403. Every field, response and error code is in the API Reference; shared errors are in Errors & Pagination.

Agencies: every endpoint on this page accepts sub_account_id, so you can build a client’s knowledge base inside their sub-account with your agency key. Send it in the body on POST/PUT and as a query parameter on GET/DELETE. See API for Agencies.

Importing costs credits. Reading a page or document and writing FAQs from it consumes credits, roughly in proportion to how much content there is. Use Estimate what an import will cost before committing to a large crawl.


How an import works

Importing is a background job, not something that finishes while you wait. Every import endpoint answers at once (202) with a source_id, and you poll that source until it is done:

  1. Start the import: POST /kb-sources/url (one page), POST /kb-sources/file (an uploaded document), or POST /kb-sources/bulk-import (up to 100 pages).
  2. Poll: GET /kb-sources/{sourceId} until status is no longer queued or processing.
  3. Read the FAQs: when the status is ready, the entries it produced are in your FAQ library (GET /faqs).
Status What it means
queued Waiting to be read. Nothing has been charged yet.
processing Being read and turned into FAQs right now.
ready Finished. Its FAQs are in your library.
failed Could not be imported. error_message says why.
cancelled Stopped before it was read (see Stop an import).
paused Waiting on you: your own AI key failed mid-import, or the website blocks automated readers and its remaining pages cost 1 extra credit each. error_message says which (see Resume a paused import).
deleting A bulk removal is working through it.
unknown The record carries no status. Treat it as not ready.

Attach as you import. Pass autoLinkToAgentId on any import endpoint and the source, plus every FAQ it produces, lands on that Agent’s knowledge in the same call. autoLinkToCampaignId does the same for a classic campaign. Linking is best effort: an ID that does not exist, or belongs to another account, is skipped silently and the import still runs, so confirm the link by reading the Agent back.


Endpoints

Task Method and path Reference
Import a web page POST /kb-sources/url Open in API Reference
Import an uploaded document POST /kb-sources/file Open in API Reference
Import many pages at once POST /kb-sources/bulk-import Open in API Reference
Check a source GET /kb-sources/{sourceId} Open in API Reference
Delete a source DELETE /kb-sources/{sourceId} Open in API Reference
Delete many sources at once POST /kb-sources/bulk-delete Open in API Reference
Discover pages on a website POST /kb-sources/discover-pages Open in API Reference
Estimate what an import will cost POST /kb-sources/estimate-cost Open in API Reference
Stop an import POST /kb-sources/cancel-import Open in API Reference
Resume a paused import POST /kb-sources/resume-import Open in API Reference
Find new pages on a website POST /kb-sources/refresh-domain Open in API Reference
Refresh every page on a website POST /kb-sources/trigger-domain-refresh Open in API Reference
Track a website refresh GET /kb-sources/domain-refresh-status Open in API Reference
Stop a website refresh POST /kb-sources/refresh-domain/cancel Open in API Reference
Refresh a single source POST /kb-sources/{sourceId}/refresh Open in API Reference
Pick the most relevant pages POST /kb-sources/select-relevant-pages Open in API Reference
Create a knowledge group POST /kb-groups Open in API Reference
Rename a knowledge group PUT /kb-groups/{groupId} Open in API Reference
Delete a knowledge group DELETE /kb-groups/{groupId} Open in API Reference
Add a FAQ to a group POST /kb-groups/{groupId}/faqs Open in API Reference
Remove a FAQ from a group DELETE /kb-groups/{groupId}/faqs/{faqId} Open in API Reference
Apply a group to an Agent POST /kb-groups/{groupId}/apply-to-agent Open in API Reference
Apply a group to a campaign (classic) POST /kb-groups/{groupId}/apply-to-campaign Open in API Reference

Import a web page

POST /kb-sources/url adds one page and answers 202 with the source_id to poll.

curl -X POST "https://api.dmchamp.com/v1/kb-sources/url?apiKey=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/pricing", "autoLinkToAgentId": "ag7HkQ2ZpLxR3mNb" }'
{ "success": true, "source_id": "kb_src_abc123", "status": "queued", "batch_id": "batch_9f2a" }
  • If the same page is already in your knowledge base, nothing new is queued: you get a 200 with status: "exists" and skipped_duplicate: 1, and an auto-link you asked for is still applied to the existing source.
  • url must be a full http or https address.

Import an uploaded document

POST /kb-sources/file adds a document that is already in your account’s file storage. Supported types: PDF, DOCX, TXT, MD, CSV and XLSX. The file type is detected from the extension in filename.

  • This endpoint does not carry the file. There is no multipart upload, no base64 body and no download from a URL: you send the storage location of a file that already exists. storage_path must begin with users/{your user id}/uploads/, or the request is refused with 403. The dashboard puts files there when you drag them in. If you have no way to place a file there, use Import a web page instead.
curl -X POST "https://api.dmchamp.com/v1/kb-sources/file?apiKey=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "storage_path": "users/abc123uid/uploads/handbook.pdf",
    "filename": "handbook.pdf",
    "mime_type": "application/pdf",
    "autoLinkToAgentId": "ag7HkQ2ZpLxR3mNb"
  }'

Check a source

GET /kb-sources/{sourceId} is the poll that follows every import and refresh. Repeat it until the status is ready or failed.

curl "https://api.dmchamp.com/v1/kb-sources/kb_src_abc123?apiKey=YOUR_API_KEY"
{ "success": true, "source_id": "kb_src_abc123", "status": "ready", "faq_count": 24, "section_count": 31, "error_message": null }

Delete a source

DELETE /kb-sources/{sourceId} removes one source. By default the FAQs it produced are kept; add delete_faqs=true to remove those as well (the response’s faqs_deleted is 0 otherwise).

Delete many sources at once (POST /kb-sources/bulk-delete, up to 2,000 IDs per call) runs in the background and emails you when it finishes. It always removes the FAQs too; there is no option to keep them. domainLabel is only a friendly name for that email.


Import many pages at once

POST /kb-sources/bulk-import adds up to 100 pages per call. It is the usual follow-up to Discover pages on a website or Find new pages on a website. Poll each ID in queued_source_ids with Check a source.

curl -X POST "https://api.dmchamp.com/v1/kb-sources/bulk-import?apiKey=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "urls": ["https://example.com/pricing", "https://example.com/faq"],
    "autoLinkToAgentId": "ag7HkQ2ZpLxR3mNb"
  }'
{ "success": true, "batch_id": "batch_9f2a", "queued": 2, "skipped_duplicate": 0, "queued_source_ids": ["kb_src_abc123", "kb_src_def456"] }

Good to know:

  • Duplicates are skipped, not imported twice, and are still linked to the Agent when you asked for that.
  • Page limit. Your account can have up to 5,000 pages waiting to be imported at once, counting pages already queued or being read. A call that would go past it is refused with 400 and error_code: kb_import_page_limit, and nothing from that call is queued. Imports above 5,000 pages need approval: contact support to have the limit raised.
  • Credit check up front. An import your account cannot pay for is refused before anything is queued, with 402 and error_code: kb_import_insufficient_credits (plus required_credits, available_credits and waiting_pages). Each page counts as at least one chunk, and pages you already have waiting count too, because they are only charged when processed. Accounts with automatic top-up are not refused on their balance. Accounts that use their own AI key are not refused either, unless they run on the Max tier, which is charged in credits. For a sub-account, available_credits is null.
  • More than 100 pages means several calls. Send the size of the whole selection as plannedTotal on the first call, so the page limit and the credit check cover the whole selection and an import that cannot finish is refused before any page is queued, instead of stopping halfway. The accepted first call returns an import_session: send it back as importSession on every later call of that selection. Those calls then skip the up-front credit check for up to the approved number of pages, for one hour. The page limit still applies, and every page is still charged when processed. Without a session (or once it expired or its pages are used up) each call gets the normal check. The older continuesImport flag is ignored.

Discover pages on a website

POST /kb-sources/discover-pages explores a site from one starting address and lists the pages it finds on the same domain, each with advice on whether it is worth importing. Nothing is imported and nothing is selected for you.

curl -X POST "https://api.dmchamp.com/v1/kb-sources/discover-pages?apiKey=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com", "maxPages": 100 }'
{
  "success": true,
  "source_type": "sitemap",
  "pages": [
    { "url": "https://example.com/pricing", "title": "Pricing", "depth": 1, "score": 95, "recommendation": "add", "reason_key": "core_page" }
  ]
}
  • Each page gets a score (0 to 100) and a recommendation: add (score 90 or above), maybe (borderline) or skip (changelogs, legal pages, duplicate translations). reason_key is a stable machine-readable reason, for example core_page, changelog_history, legal_page or locale_duplicate.
  • maxPages defaults to your import limit (5,000) and cannot be higher; a higher value is refused with 400 and kb_import_page_limit. Discovery never goes past 10,000 pages. When the site has more pages than the limit, limit_reached is true and only the first max_pages come back.
  • Exploration is best effort. If the site cannot be read the response is still 200, with success: false, an empty pages list and an error. Check success before reading pages.

Estimate what an import will cost

POST /kb-sources/estimate-cost works out the credits a proposed import would consume. Pages are fetched and documents read to measure their size, but nothing is imported and the estimate itself spends no credits. Send urls, files (already uploaded), or both; pass tier so the estimate matches the AI quality tier you will be charged on.

curl -X POST "https://api.dmchamp.com/v1/kb-sources/estimate-cost?apiKey=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "urls": ["https://example.com/pricing"] }'
{
  "success": true,
  "estimates": [{ "ref": "https://example.com/pricing", "chunks": 7, "credits": 7 }],
  "total_credits": 7, "affordable": true, "available_credits": 120,
  "waiting_pages": 0, "max_affordable_chunks": 120
}
  • Each row echoes your URL or storage path in ref. A page or file that could not be read still gets a row, counted as one chunk, with an error on it.
  • affordable counts the pages you already have waiting (waiting_pages). To estimate a big selection in several calls, compare a running total against max_affordable_chunks, or send the earlier calls’ chunks as prior_chunks (they count only towards affordable).
  • max_affordable_chunks is null when your balance does not limit you (automatic top-up, or your own AI key below the Max tier), and always null for a sub-account, which gets affordable only and a null available_credits.

Stop an import

POST /kb-sources/cancel-import stops pages still waiting in the queue, for a crawl that turned out bigger than expected. Pass host (for example docs.example.com) to stop only that site; leave it out to stop every waiting import on the account.

  • Cancelling a waiting page costs nothing, because it has not been read yet.
  • Pages already being processed are not stopped: their work is under way and charged either way. The response reports them as in_flight next to cancelled.

Resume a paused import

POST /kb-sources/resume-import restarts an import that was paused because your own AI key stopped working (optionally only for one host).

It also restarts pages paused because the website blocks automated readers. For those pages the call is your consent to the 1 extra credit per page. Send retry_without_charge: true to read them again at no charge instead (for example after you switched off the bot protection on the site). To leave them out, delete the paused sources.

  • Calling it is your consent to finish the import on whichever key is live now, which may mean spending platform credits if your own key is still down.

Keep a website up to date

Three separate calls, so looking costs nothing:

  1. Find new pages on a website (POST /kb-sources/refresh-domain) explores a site you already imported from and reports only the pages that are not in your knowledge base yet, with the same advice as discovery. Nothing is imported or changed. Import the ones you want with Import many pages at once.
  2. Refresh every page on a website (POST /kb-sources/trigger-domain-refresh) re-reads every page you already imported from that site: changed sections are updated, new ones added, removed ones dropped. It queues the work and returns at once.
  3. Track a website refresh (GET /kb-sources/domain-refresh-status?baseUrl=...) shows progress, and Stop a website refresh (POST /kb-sources/refresh-domain/cancel) stops it.

baseUrl can be any address on the site, or just the host.

curl -X POST "https://api.dmchamp.com/v1/kb-sources/trigger-domain-refresh?apiKey=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "baseUrl": "https://example.com" }'

curl "https://api.dmchamp.com/v1/kb-sources/domain-refresh-status?baseUrl=https://example.com&apiKey=YOUR_API_KEY"
{ "success": true, "job": { "domainBatchId": "job_7c1e", "total": 249, "pending": 28, "succeeded": 219, "failed": 2, "status": "refreshing" } }

Good to know:

  • Find new pages never queues anything. new_urls_queued is always 0 (kept for backwards compatibility), and existing_refresh_queued only counts the pages you already have that are ready to be re-read. Like discovery, it fails softly (200, success: false, empty new_pages) and uses the same page limits.
  • Progress: pages finished is total minus pending. The job status moves through refreshing, then deduplicating (the clean-up pass at the end), then a final completed, failed or cancelled. job is null when no refresh is running for that site. Keep domainBatchId: it is the jobId you pass to the cancel call.
  • Stopping: pages already finished keep their updated content, pages not started are dropped, and pages being re-read go back to their previous state (sources_reset); brand-new pages of this refresh that were still queued are cancelled (sources_cancelled). Cancelling twice is harmless. Once the refresh reached its clean-up pass it can no longer be stopped: the response is success: false with reason: "already_finalizing".

Refresh a single source (POST /kb-sources/{sourceId}/refresh) re-reads one page you already imported the same way, and answers 202; poll it with Check a source.

Pick the most relevant pages

POST /kb-sources/select-relevant-pages asks the AI to pick the five pages, out of your candidate urls, that best describe the business behind homeUrl. It is used when generating a campaign playbook from a website, and it consumes credits. It is a helper, not a resource: on failure it still answers 200 with success: false, an empty pages list and an error.


Knowledge groups

A knowledge group is a named bundle of FAQs (“Shipping and returns”, “Onboarding”) that you can apply to an Agent or a campaign in one call. The group holds references, not copies: the FAQs stay in your single library, so editing one with the FAQs API updates it everywhere it is used.

  • A new group starts empty. Add a FAQ to a group with its faq_id.
  • Adding a FAQ to a group only changes the bundle; it does not attach the FAQ to any Agent. Apply a group to an Agent for that.
  • Applying only ever adds what is missing, so applying the same group twice is harmless: added_count is 0 when the group is empty or already applied.
  • Removing a FAQ from a group does not delete the FAQ, and Agents the group was already applied to keep it. Deleting a group removes only the bundle; its FAQs stay in your library and anything it was applied to keeps them. Renaming leaves the FAQs untouched.
  • On an Agent based account use the Agent call; the campaign call is the classic-campaign version.

Add a FAQ to a group

curl -X POST "https://api.dmchamp.com/v1/kb-groups/kbg_abc123/faqs?apiKey=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "faq_id": "aBcD1234eFgH5678" }'

Apply a group to an Agent

curl -X POST "https://api.dmchamp.com/v1/kb-groups/kbg_abc123/apply-to-agent?apiKey=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "agent_id": "ag7HkQ2ZpLxR3mNb" }'
{ "success": true, "group_id": "kbg_abc123", "agent_id": "ag7HkQ2ZpLxR3mNb", "added_count": 12 }

Errors

Status When it happens on a knowledge base endpoint
400 A required field is missing or invalid: an empty url, a missing baseUrl or jobId, more than 100 URLs in a bulk import, more than 2,000 IDs in a bulk delete, a file type we cannot read, or the page limit (kb_import_page_limit).
402 Not enough credits to run the import (kb_import_insufficient_credits). Top up and try again.
403 A storage_path outside your own uploads folder, or your plan does not include API access.
404 The source, group, FAQ, Agent, campaign or refresh job was not found: it does not exist or belongs to another account.

Soft failures are not errors. Discovery (discover-pages, refresh-domain) and the page-picking helper answer 200 with success: false and an error when the website cannot be read. Always check success before reading the data.