v1.0.0 Public Access

Sri Lankan Bus Fare API

A comprehensive REST API for calculating bus fares across Sri Lanka. Supports multilingual stop name search (Sinhala, English, Tamil) and returns all available routes between two stops with their respective fares.


Getting Started

This API is hosted and managed by us. You do not need to install or deploy anything. To start using the API, you only need your API key.

Get Your API Key

Please contact us to obtain your unique sk_live_... API key. You will need this key to authenticate all your requests.


API Reference

Base URL

https://busfare.dinukasandeepa.com/api
POST/fare

Calculate Fare

Calculate bus fare between two stops. Returns all available routes with their fares.

Headers

x-api-key
Required
Your unique API key
Content-Type
Required
application/json

Body Parameters

start
string
Starting stop name (Sinhala, English, or Tamil)
end
string
Ending stop name (Sinhala, English, or Tamil)

Example Request

English
bash
curl -X POST https://busfare.dinukasandeepa.com/api/fare \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{"start": "Monaragala", "end": "Ampara Bus Stand"}'

Success Response

json
{
  "results": [
    {
      "routeId": "909",
      "routeName": "මොණරාගල - අම්පාර බස් නැවතුම්පොල",
      "routeNameEnglish": "Monaragala - Ampara Bus Stand",
      "routeNameTamil": "மொனராகலை - அம்பாறை பேருந்து நிலையம்",
      "category": "Normal",
      "startStop": {
        "name": "මොණරාගල",
        "englishName": "Monaragala",
        "tamilName": "மொனராகலை",
        "instance": 0
      },
      "endStop": {
        "name": "අම්පාර බස් නැවතුම්පොල",
        "englishName": "Ampara Bus Stand",
        "tamilName": "அம்பாரா பேருந்து நிலையம்",
        "instance": 48
      },
      "distanceStages": 48,
      "fare": 337,
      "currency": "LKR"
    }
  ],
  "query": {
    "start": "Monaragala",
    "end": "Ampara Bus Stand"
  },
  "totalRoutes": 1
}

Client Integration Guide

1. Get an API Key

You must obtain a valid API key (sk_live_...) to access the API.

2. Configure Your Project

Store the API key securely in your project's environment variables.

env
BUSFAIR_API_KEY="sk_live_..."

3. Make API Requests

You must include the x-api-key header in every request.

Node.js (Fetch)

javascript
const API_KEY = process.env.BUSFAIR_API_KEY;

async function getFare(start, end) {
  const response = await fetch('https://busfare.dinukasandeepa.com/api/fare', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'x-api-key': API_KEY
    },
    body: JSON.stringify({ start, end })
  });

  const data = await response.json();
  console.log(data);
}

Python (Requests)

python
import os
import requests

api_key = os.getenv('BUSFAIR_API_KEY')

response = requests.post(
    'https://busfare.dinukasandeepa.com/api/fare',
    headers={
        'Content-Type': 'application/json',
        'x-api-key': api_key
    },
    json={'start': 'Monaragala', 'end': 'Ampara'}
)

print(response.json())

Data Model

Routes Object

javascript
{
  "routeId": "909",
  "routeName": "මොණරාගල - අම්පාර",           // Sinhala
  "routeNameEnglish": "Monaragala - Ampara", // English
  "routeNameTamil": "மொனராகலை - அம்பாறை",     // Tamil
  "category": "Normal",
  "startStop": {
      "name": "මොණරාගල",           // Sinhala
      "englishName": "Monaragala", // English
      "tamilName": "மொனராகலை",      // Tamil
      "instance": 0                // Position on route
  },
  "endStop": {
      "name": "අම්පාර බස් නැවතුම්පොල",
      "englishName": "Ampara Bus Stand",
      "tamilName": "அம்பாரா பேருந்து நிலையம்",
      "instance": 48
  },
  "distanceStages": 48,
  "fare": 337,
  "currency": "LKR"
}