πŸ“šKalopati API Documentation

Complete guide for developers to integrate with Kalopati APIs

πŸš€ Introduction

Welcome to the Kalopati API documentation. This RESTful API provides access to posts, categories, and content data. All responses are in JSON format.

Note: The API uses a custom REST URL prefix kp_api instead of the default WordPress wp-json.

🌐 Base URL

All API endpoints are relative to:

https://kalopati.com/kp_api/

Base URL for all API endpoints.

πŸ“‘ WordPress RSS Feeds

In addition to the custom REST APIs, Kalopati provides standard WordPress RSS feeds for easy content syndication. RSS feeds are XML-based and compatible with all RSS readers and aggregators.

Main RSS Feed

GET
/feed/

Returns all recent posts in RSS 2.0 format.

Full URL Example

https://kalopati.com/feed/

Atom Feed

GET
/feed/atom/

Returns all recent posts in Atom 1.0 format.

Category RSS Feed

GET
/category/{category-slug}/feed/

Returns posts from a specific category.

Example

// Get RSS feed for "politics" category https://kalopati.com/category/politics/feed/

Comments RSS Feed

GET
/comments/feed/

Returns recent comments across all posts.

Post Comments Feed

GET
/{post-slug}/feed/

Returns comments for a specific post.

RSS Feed Features

Feature Description
Format XML (RSS 2.0 or Atom 1.0)
Default Posts 10 most recent posts
Content Title, description, link, publication date, author
Images Featured images included in content
Updates Automatically updates when new content is published

Parsing RSS in Code

JavaScript Example

// Using RSS parser library const Parser = require('rss-parser'); const parser = new Parser(); (async () => { const feed = await parser.parseURL('https://kalopati.com/feed/'); console.log(feed.title); feed.items.forEach(item => { console.log(item.title + ':' + item.link); }); })();

Python Example

import feedparser # Parse RSS feed feed = feedparser.parse('https://kalopati.com/feed/') print(f"Feed Title: {feed.feed.title}") print(f"Number of posts: {len(feed.entries)}") for entry in feed.entries: print(f"\nTitle: {entry.title}") print(f"Link: {entry.link}") print(f"Published: {entry.published}") print(f"Summary: {entry.summary[:100]}...")

PHP Example

<?php // Load RSS feed $rss = simplexml_load_file('https://kalopati.com/feed/'); echo "Feed Title: " . $rss->channel->title . "\n\n"; foreach ($rss->channel->item as $item) { echo "Title: " . $item->title . "\n"; echo "Link: " . $item->link . "\n"; echo "Date: " . $item->pubDate . "\n\n"; } ?>
Tip: RSS feeds are perfect for content aggregators, news readers, and simple integrations. For more advanced features and filtering, use the REST API endpoints described below.

πŸ” Authentication

Currently, these APIs are publicly accessible and do not require authentication. They are read-only endpoints that return publicly available content.

βš™οΈ REST API Endpoints

These endpoints provide access to posts, categories, and content data via the Kalopati REST API. They can be used in any application, website, or service.

Get Recent Posts

GET
/kp_api/app/v1/posts

Description

Returns 10 most recent posts.

Response Fields

Field Type Description
title String The post title
newsUrl String Permalink to the full article
thumbnailUrl String URL of the featured image (large size)
newsOverView String Formatted full content with paragraphs
publishedDate String (ISO 8601) Publication date in Asia/Kathmandu timezone
videoUrl String (optional) YouTube or Facebook video URL if found in content

Get All Categories

GET
/kp_api/app/v1/categories

Description

Returns a list of all available categories with their IDs and slugs.

Response Fields

Field Type Description
Category ID Integer The unique category identifier
Category Name String The display name of the category
Category Slug String The URL-friendly category identifier

Example Response

[ { "Category ID": 1, "Category Name": "Politics", "Category Slug": "politics" }, { "Category ID": 5, "Category Name": "Sports", "Category Slug": "sports" } ]

Get Posts by Category

GET
/kp_api/app/v1/get-category/{catid}/{numpost}

Description

Returns posts from a specific category. Includes video URLs if embedded in the content.

URL Parameters

Parameter Type Required Description
catid Integer Required Category ID to fetch posts from (must be positive integer)
numpost Integer Required Number of posts to return (max: 100, will be capped if exceeded)

Example Request

// Get 15 posts from category ID 5 GET /kp_api/app/v1/get-category/5/15

Response Fields

Same as Recent Posts, plus:

Field Type Description
videoUrl String (optional) YouTube or Facebook video URL if found in content

πŸ“‹ Response Format

All successful API responses return:

Input Validation

The API validates all input parameters:

Example Error Response

{ "code": "invalid_category", "message": "Category ID must be a positive integer", "data": { "status": 400 } }

Date Format

All dates are returned in ISO 8601 format with Asia/Kathmandu timezone (+05:45):

"2026-02-03T14:30:00+05:45"

πŸ’» Code Examples

JavaScript / Fetch API

// Fetch recent news fetch('https://kalopati.com/kp_api/news-recent/v1/posts') .then(response => response.json()) .then(data => { console.log('Recent News:', data); data.forEach(post => { console.log(post.title); }); }) .catch(error => console.error('Error:', error));

JavaScript / Axios

const axios = require('axios'); // Get posts by category async function getCategoryPosts(categoryId, count) { try { const response = await axios.get( `https://kalopati.com/kp_api/app/v1/get-category/${categoryId}/${count}` ); return response.data; } catch (error) { console.error('Error fetching posts:', error); } } // Usage getCategoryPosts(5, 10).then(posts => { console.log(posts); });

Python / Requests

import requests # Get recent news url = 'https://kalopati.com/kp_api/news-recent/v1/posts' response = requests.get(url) if response.status_code == 200: posts = response.json() for post in posts: print(f"Title: {post['title']}") print(f"URL: {post['newsUrl']}") print("-" * 50) else: print(f"Error: {response.status_code}")

PHP / cURL

<?php // Get all categories $url = 'https://kalopati.com/kp_api/app/v1/categories'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); $categories = json_decode($response, true); foreach ($categories as $category) { echo $category['Category Name'] . " (ID: " . $category['Category ID'] . ")\n"; } ?>

Swift / iOS

import Foundation // Fetch recent posts func fetchRecentPosts() { guard let url = URL(string: "https://kalopati.com/kp_api/app/v1/posts") else { return } let task = URLSession.shared.dataTask(with: url) { data, response, error in if let error = error { print("Error: \(error)") return } guard let data = data else { return } do { let posts = try JSONSerialization.jsonObject(with: data) print(posts) } catch { print("JSON Error: \(error)") } } task.resume() }

Java / Android

import java.net.HttpURLConnection; import java.net.URL; import java.io.BufferedReader; import java.io.InputStreamReader; public class NewsAPIClient { public static String getCategoryPosts(int categoryId, int count) { try { String urlString = String.format( "https://kalopati.com/kp_api/app/v1/get-category/%d/%d", categoryId, count ); URL url = new URL(urlString); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); BufferedReader reader = new BufferedReader( new InputStreamReader(conn.getInputStream()) ); StringBuilder response = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { response.append(line); } reader.close(); return response.toString(); } catch (Exception e) { e.printStackTrace(); return null; } } }

Kotlin / Android

import kotlinx.coroutines.* import java.net.URL // Using Coroutines suspend fun fetchCategories(): String = withContext(Dispatchers.IO) { val url = "https://kalopati.com/kp_api/app/v1/categories" try { URL(url).readText() } catch (e: Exception) { e.printStackTrace() "" } } // Usage in Activity/Fragment lifecycleScope.launch { val categories = fetchCategories() // Process categories }

⚠️ Error Handling

Common HTTP Status Codes

Status Code Meaning Description
200 OK Request successful
400 Bad Request Invalid input parameters (validation errors)
404 Not Found Endpoint doesn't exist or invalid route parameters
500 Internal Server Error Server-side error occurred

Best Practices

Error Handling Example

// JavaScript error handling example async function fetchNewsWithErrorHandling() { try { const response = await fetch( 'https://kalopati.com/kp_api/news-recent/v1/posts', { signal: AbortSignal.timeout(30000) // 30 second timeout } ); if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`); } const data = await response.json(); if (!Array.isArray(data)) { throw new Error('Invalid response format'); } if (data.length === 0) { console.log('No news available'); return []; } return data; } catch (error) { if (error.name === 'TimeoutError') { console.error('Request timed out'); } else if (error.name === 'TypeError') { console.error('Network error'); } else { console.error('Error:', error.message); } return null; } }

πŸ“ž Support & Contact

If you encounter any issues or have questions about the API:

Version: This documentation reflects the current API implementation as of February 2026. Always test with the latest endpoints in your production environment.