Appearance
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
| Entry | Recommended use | Documentation |
|---|---|---|
| API page | A standalone URL that returns JSON or handles a form | CMS: Open APIs · k.api |
| CodeBlock | Reuse the same logic from several pages or APIs | CMS: Code · k.site.codes |
| Scheduled job | Periodic synchronization, cleanup, or notifications | CMS: 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
| Item | Details |
|---|---|
| Route | Give the API a stable URL such as /api/news |
| Input | Read query parameters, body, headers, or files from k.request |
| Business data | Retrieve data with k.content, k.DB, or an external service |
| Output | Return JSON, a redirect, or a status code with k.response |
| Permissions | Read k.session or account APIs when authentication is required |
| Logging | Write important failure paths to k.logger |
Coordinate with Admin Configuration
| Goal | Configure first |
|---|---|
| Read a content list | Content Types and Content Folders |
| Send email | k.mail |
| Start a payment | Payment Integration and k.payment |
| Call an external service | Open APIs or k.net.httpClient |
| Store business data | Database and k.DB |
Debugging Recommendations
- Return a fixed value first to confirm that the route is accessible.
- Connect the real data query next.
- Return an explicit status code and JSON body for each error path.
- Finally, call the API from the page and inspect the browser Network panel.