Skip to content

Write Your First KScript API

Add a server-side endpoint to Kooboo so the frontend can retrieve JSON or execute business logic.

Choose an Entry Point

EntryRecommended useDocumentation
API pageA standalone URL that returns JSON or handles a formCMS: Open APIs · k.api
CodeBlockReuse the same logic from several pages or APIsCMS: Code · k.site.codes
Scheduled jobPeriodic synchronization, cleanup, or notificationsCMS: Jobs · k.site.runJob

For your first attempt, start with an API page: enter a URL, save the script, and call it from the browser or a frontend fetch request.

What a Minimal API Must Consider

ItemDetails
RouteGive the API a stable URL such as /api/news
InputRead query parameters, body, headers, or files from k.request
Business dataRetrieve data with k.content, k.DB, or an external service
OutputReturn JSON, a redirect, or a status code with k.response
PermissionsRead k.session or account APIs when authentication is required
LoggingWrite important failure paths to k.logger

Coordinate with Admin Configuration

GoalConfigure first
Read a content listContent Types and Content Folders
Send emailk.mail
Start a paymentPayment Integration and k.payment
Call an external serviceOpen APIs or k.net.httpClient
Store business dataDatabase and k.DB

Debugging Recommendations

  1. Return a fixed value first to confirm that the route is accessible.
  2. Connect the real data query next.
  3. Return an explicit status code and JSON body for each error path.
  4. Finally, call the API from the page and inspect the browser Network panel.