POST
/auth/login
Auth Required

User Login

Authenticate user and return JWT token. Use this endpoint to obtain a bearer token for subsequent API calls.

Rate Limit: 10 per minute

Request/Response Examples

Send username and password to authenticate.

JSON
{
    "username": "admin",
    "password": "Admin@123"
}

Successful authentication returns JWT token.

JSON
{
    "status": "success",
    "data": {
        "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
        "user": {
            "id": 1,
            "username": "admin",
            "email": "admin@hotel.com"
        },
        "expires_in": 86400
    },
    "code": 200
}

Code Examples

PHP - Login

PHP example for authentication

<?php
$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://hotel.webninjaafrica.com/api/auth/login",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode([
        "username" => "admin",
        "password" => "Admin@123"
    ]),
    CURLOPT_HTTPHEADER => ["Content-Type: application/json"]
]);

$response = curl_exec($curl);
$data = json_decode($response, true);

if ($data["status"] === "success") {
    $token = $data["data"]["token"];
    echo "Login successful! Token: " . $token;
}

curl_close($curl);
?>
Python - Login

Python example for authentication

import requests

url = "https://hotel.webninjaafrica.com/api/auth/login"
payload = {
    "username": "admin",
    "password": "Admin@123"
}

response = requests.post(url, json=payload)
data = response.json()

if data["status"] == "success":
    token = data["data"]["token"]
    print(f"Login successful! Token: {token}")
else:
    print("Login failed: " + data["message"])
Node.js - Login

Node.js example for authentication

const axios = require("axios");

async function login() {
    try {
        const response = await axios.post("https://hotel.webninjaafrica.com/api/auth/login", {
            username: "admin",
            password: "Admin@123"
        });
        
        if (response.data.status === "success") {
            const token = response.data.data.token;
            console.log(`Login successful! Token: ${token}`);
            return token;
        }
    } catch (error) {
        console.error("Login failed:", error.response?.data?.message || error.message);
    }
}

login();
cURL - Login

cURL example for authentication

curl -X POST https://hotel.webninjaafrica.com/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username":"admin","password":"Admin@123"}'