VPS.org API

REST API ලේඛන

ගිණුම් API

ගිණුම් පැතිකඩ සහ API ටොකන් තොරතුරු ලබා ගන්න. API ටොකන් සමග සම්බන්ධ වන ගිණුම් සහ බලපත්ර හඳුනා ගැනීම සඳහා ප්රයෝජනවත්.

අන්ත ලක්ෂ්‍ය 1 අවසන් බිංදුව
පාදක මාර්ගය /api/v1/account
ලබා ගන්න /api/v1/account/me/

ගිණුම් සහ ටොකන් තොරතුරු ලබාගන්න

ඉල්ලීම භාවිතා API ටෝකන් සඳහා ගිණුම් පැතිකඩ මෙටා දත්ත සහ ටෝකන් විෂය පථය / අවසර ආපසු. ඔබ බහු API ටෝකන් කළමනාකරණය සහ ටෝකන් අයිති වන ගිණුම හඳුනා ගැනීමට අවශ්ය විට මෙම ප්රයෝජනවත් වන අතර එය ඇති අවසර මොනවාද.

සත්‍යාපනය

වලංගු API ටොකන් අවශ්ය. ඕනෑම සක්‍රීය ටොකන් එහි අවසර විෂය පථය නොසලකා මෙම අවසන් ස්ථානයට පිවිසිය හැක.

උදාහරණ ඉල්ලීම

cURL
Python
JavaScript
PHP
curl -X GET "https://admin.vps.org/api/v1/account/me/" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json"
import requests

url = "https://admin.vps.org/api/v1/account/me/"
headers = {
    "Authorization": "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json"
}

response = requests.get(url, headers=headers)
data = response.json()

print(f"Account: {data['account']['email']}")
print(f"Token: {data['token']['name']}")
print(f"Permissions: {data['token']['permissions']}")
const response = await fetch('https://admin.vps.org/api/v1/account/me/', {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer YOUR_API_TOKEN',
    'Content-Type': 'application/json'
  }
});

const data = await response.json();
console.log(`Account: ${data.account.email}`);
console.log(`Token: ${data.token.name}`);
console.log(`Permissions:`, data.token.permissions);
$ch = curl_init('https://admin.vps.org/api/v1/account/me/');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer YOUR_API_TOKEN',
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

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

echo "Account: " . $data['account']['email'] . "\n";
echo "Token: " . $data['token']['name'] . "\n";
echo "Permissions: " . implode(', ', $data['token']['permissions']) . "\n";

උදාහරණ ප්‍රතිචාරය

{
  "account": {
    "email": "john@example.com",
    "first_name": "John",
    "last_name": "Doe",
    "company_name": "Acme Inc.",
    "created_at": "2024-06-15"
  },
  "token": {
    "name": "Production Deploy Key",
    "permissions": [
      "servers:list",
      "servers:create",
      "servers:power",
      "dns:*"
    ],
    "created_at": "2025-01-10T14:30:00Z",
    "last_used_at": "2025-02-11T08:45:12Z",
    "expires_at": null,
    "is_expired": false
  }
}

ප්‍රතිචාර ක්ෂේත්‍ර

account object
ක්ෂේත්‍රය වර්ගය විස්තරය
email string Account email address
first_name string | null Account holder's first name
last_name string | null Account holder's last name
company_name string | null Company name (if set)
created_at date Account creation date (YYYY-MM-DD)
token object
ක්ෂේත්‍රය වර්ගය විස්තරය
name string Name assigned to this API token
permissions array List of permission strings (e.g. servers:list, dns:*). See Authentication docs for permission format.
created_at datetime When the token was created (ISO 8601)
last_used_at datetime | null Last time the token was used for authentication
expires_at datetime | null Token expiration date (null if no expiration)
is_expired boolean Whether the token has expired

ප්‍රතිචාර තත්ව කේත

200 Successfully retrieved account and token information
401 Unauthorized - Invalid, expired, or missing API token

පොදු භාවිතය නඩු

ටොකන් හිමිකරු හඳුනාගන්න

විවිධ යෙදුම් හරහා බහු API ටොකන් කළමනාකරණය කරන විට, ටොකන් අයත් වන ගිණුම තහවුරු කිරීමට මෙම අවසන් ස්ථානය භාවිතා කරන්න:

# Check which account this token is associated with
response = requests.get(
    "https://admin.vps.org/api/v1/account/me/",
    headers={"Authorization": f"Bearer {api_token}"}
)
account = response.json()["account"]
print(f"This token belongs to: {account['email']}")

ටොකන් අවසර තහවුරු කරන්න

API ඇමතුම් කිරීමට පෙර, වත්මන් ටොකන් ඇති අවසර පරීක්ෂා කරන්න:

# Check token permissions before performing an action
response = requests.get(
    "https://admin.vps.org/api/v1/account/me/",
    headers={"Authorization": f"Bearer {api_token}"}
)
permissions = response.json()["token"]["permissions"]

if "servers:create" in permissions or "servers:*" in permissions:
    # Token has permission to create servers
    create_server()
else:
    print("Token does not have servers:create permission")

ටොකන් කල් ඉකුත්වීම නිරීක්‍ෂණය කරන්න

ඔබේ ටොකනය කල් ඉකුත් වීමට ළඟා වී ඇතිදැයි පරීක්ෂා කරන්න:

from datetime import datetime

response = requests.get(
    "https://admin.vps.org/api/v1/account/me/",
    headers={"Authorization": f"Bearer {api_token}"}
)
token_info = response.json()["token"]

if token_info["expires_at"]:
    expires = datetime.fromisoformat(token_info["expires_at"])
    days_left = (expires - datetime.now()).days
    if days_left < 7:
        print(f"Warning: Token expires in {days_left} days")
else:
    print("Token has no expiration date")

අවසර උපුටාදැක්වීම්

අවසර සංයුතිය අනුගමනය කරන්න resource:action. භාවිතය resource:* සම්පතක් සඳහා පූර්ණ ප්රවේශය සඳහා, හෝ *:* සම්පූර්ණ API ප්රවේශය සඳහා.

සම්පත භාවිතයට ඇති ක්‍රියා
servers list, create, update, delete, power, backup, snapshot, resize, *
domains list, search, update, renew, *
dns list, create, update, delete, *
snapshots list, delete, *
backups list, *
ssh-keys list, create, delete, *
plans list, *
locations list, *
deployments list, create, delete, *
billing list, *
Manage your tokens: Create, edit, and revoke API tokens at admin.vps.org/account/developers/