Lunos

Documentation

Balance API

The Balance API allows you to retrieve the current balance and balance-related settings for the authenticated user.

Authentication Required: This endpoint requires a valid secret key for authentication.

GET /v1/balance

Retrieves the current balance and balance-related settings for the authenticated user.

GET https://api.lunos.tech/v1/balance

Authentication

This endpoint requires authentication using a secret key in the Authorization header.

Headers

HeaderTypeRequiredDescription
AuthorizationstringYesBearer token containing your secret key

Example Request

cURL Example
1curl -X GET "https://api.lunos.tech/v1/balance" \
2  -H "Authorization: Bearer YOUR_SECRET_KEY" \
3  -H "Content-Type: application/json"

Response

Success Response

Success Response
1{
2   "success": true,
3   "message": "Balance retrieved successfully",
4   "data": {
5      "balance": 10.5,
6      "email": "user@example.com",
7      "alertBalance": 1.0,
8      "enableAlert": 1,
9      "updatedAt": "2024-01-15T10:30:00.000Z",
10      "isAlertEnabled": true,
11      "isBalanceLow": false
12   }
13}

Response Fields

FieldTypeDescription
successbooleanIndicates if the request was successful
messagestringSuccess message describing the operation
data.balancenumberCurrent balance in credits
data.emailstringUser's email address
data.alertBalancenumberThreshold for balance alerts
data.enableAlertnumberWhether alerts are enabled (1 = enabled, 0 = disabled)
data.updatedAtstringLast update timestamp
data.isAlertEnabledbooleanWhether balance alerts are enabled
data.isBalanceLowbooleanWhether balance is below the alert threshold

Error Responses

401 Unauthorized - Missing or Invalid Secret Key

401 Error Response
1{
2   "success": false,
3   "message": "Missing or invalid secret key",
4   "error": "UNAUTHORIZED"
5}

401 Unauthorized - Secret Key Expired

401 Expired Key Response
1{
2   "success": false,
3   "message": "Secret key expired",
4   "error": "UNAUTHORIZED"
5}

500 Internal Server Error

500 Error Response
1{
2   "success": false,
3   "message": "Internal server error",
4   "error": "INTERNAL_ERROR"
5}

Code Examples

JavaScript/Node.js

JavaScript Example
1const response = await fetch('https://api.lunos.tech/v1/balance', {
2   method: 'GET',
3   headers: {
4      'Authorization': 'Bearer YOUR_SECRET_KEY',
5      'Content-Type': 'application/json'
6   }
7});
8
9const data = await response.json();
10console.log('Current balance:', data.data.balance);

Python

Python Example
1import requests
2
3response = requests.get(
4    'https://api.lunos.tech/v1/balance',
5    headers={
6        'Authorization': 'Bearer YOUR_SECRET_KEY',
7        'Content-Type': 'application/json'
8    }
9)
10
11data = response.json()
12print(f"Current balance: {data['data']['balance']}")

PHP

PHP Example
1<?php
2$ch = curl_init();
3curl_setopt($ch, CURLOPT_URL, 'https://api.lunos.tech/v1/balance');
4curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
5curl_setopt($ch, CURLOPT_HTTPHEADER, [
6    'Authorization: Bearer YOUR_SECRET_KEY',
7    'Content-Type: application/json'
8]);
9
10$response = curl_exec($ch);
11curl_close($ch);
12
13$data = json_decode($response, true);
14echo "Current balance: " . $data['data']['balance'];
15?>

Note: If no balance record exists for the user, one will be automatically created with 0 balance.

For more information about other API endpoints, please refer to: