GET
/branches
Auth Required

List Branches

Get a paginated list of all hotel branches.

Scopes: branch:read
Rate Limit: 60 per minute

Request/Response Examples

Paginated list of branches.

JSON
{
    "status": "success",
    "data": {
        "data": [
            {
                "id": 1,
                "branch_code": "NRB001",
                "branch_name": "Nairobi City Hotel",
                "location": "Nairobi CBD",
                "is_active": true
            }
        ],
        "pagination": {
            "current_page": 1,
            "per_page": 15,
            "total": 6
        }
    },
    "code": 200
}

Code Examples

PHP - List Branches

PHP example for listing branches

<?php
$api_url = "https://hotel.webninjaafrica.com/api";
$token = "YOUR_JWT_TOKEN_HERE";

$ch = curl_init($api_url . "/branches?page=1&per_page=15");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Authorization: Bearer " . $token,
    "Content-Type: application/json"
));

$response = curl_exec($ch);
$branches = json_decode($response, true);
curl_close($ch);

if ($branches["status"] === "success") {
    foreach ($branches["data"]["data"] as $branch) {
        echo $branch["branch_name"] . " - " . $branch["location"] . "\n";
    }
}
?>
Python - List Branches

Python example for listing branches

import requests

token = "YOUR_JWT_TOKEN_HERE"
url = "https://hotel.webninjaafrica.com/api/branches"
headers = {
    "Authorization": "Bearer " + token,
    "Content-Type": "application/json"
}

response = requests.get(url, headers=headers, params={"page": 1, "per_page": 15})
data = response.json()

if data["status"] == "success":
    for branch in data["data"]["data"]:
        print(branch["branch_name"] + " - " + branch["location"])
else:
    print("Error: " + data["message"])
Node.js - List Branches

Node.js example for listing branches

const axios = require("axios");

async function getBranches(token) {
    try {
        const response = await axios.get("https://hotel.webninjaafrica.com/api/branches", {
            headers: { "Authorization": "Bearer " + token },
            params: { page: 1, per_page: 15 }
        });
        
        if (response.data.status === "success") {
            response.data.data.data.forEach(function(branch) {
                console.log(branch.branch_name + " - " + branch.location);
            });
        }
    } catch (error) {
        console.error("Error:", error.response?.data?.message || error.message);
    }
}
cURL - List Branches

cURL example for listing branches

curl -X GET "https://hotel.webninjaafrica.com/api/branches?page=1&per_page=15" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json"