VPS.org API

REST API ကိုစာရွက်စာတမ်းများ

အကောင့် API

အကောင့် profile ကိုနှင့် API token အချက်အလက်များကိုရယူပါ. မည်သည့်အကောင့်နှင့်ခွင့်ပြုချက်တစ်ခု API token နဲ့ဆက်စပ်နေကြသည်ကိုခွဲခြားသတ်မှတ်ရန်အသုံးဝင်သော.

အဆုံးမှတ်များ 1 ဆုံးဖြတ်ချက်
အခြေခံလမ်းကြောင်း /api/v1/account
ရယူပါ /api/v1/account/me/

အကောင့်နှင့် တန်ဖိုးဆိုင်ရာ အချက်အလက်များ

တောင်းဆိုမှုတွင်အသုံးပြုသော API ကို token ကိုများအတွက်အကောင့် profile ကို metadata နှင့် token scope / permissions ကိုပြန်ပေး. သင်က multiple API ကို tokens ကိုစီမံခန့်ခွဲတဲ့အခါမှာဤသည်အသုံးဝင်သည်နှင့်တစ်ဦး token ကိုပိုင်ဆိုင်သောမည်သည့်အကောင့်ကိုခွဲခြားသတ်မှတ်ရန်လိုအပ်သည်နှင့်မည်သည့်ခွင့်ပြုချက်ရှိသည်.

အထောက်အထားစိစစ်ခြင်း

မှန်ကန်တဲ့ API token ကိုလိုအပ်သည်။ မည်သည့်သက်ဝင်သော token သည်၎င်း၏ခွင့်ပြုချက်နယ်ပယ်နှင့်မဆိုင်ဘဲဤအဆုံးအဖြတ်ကိုဝင်ရောက်နိုင်သည်။

နမူနာတောင်းဆိုချက်

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": null
  }
}

တုံ့ပြန်မှု ကွက်လပ်များ

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 | null token သက်တမ်းကုန်ပြီလား။ token သက်တမ်းကုန်ချိန်မရှိရင် null ဖြစ်ပါတယ်။

တုံ့ပြန်မှု အခြေအနေ ကုဒ်များ

200 Successfully retrieved account and token information
403 မမှန်ကန်, သက်တမ်းကုန်ဆုံးသို့မဟုတ်ပျောက်ဆုံး API ကို token ကို။ အဆိုပါ API ကိုဖြေဆို 403, မဟုတ် 401, authentication မအောင်မြင်သောအခါ။

အများသုံးဖြစ်ရပ်များ

ပိုင်ရှင်ကို သတ်မှတ်ပါ

ကွဲပြားခြားနားသော application များအကြား API tokens များကိုစီမံခန့်ခွဲတဲ့အခါ, တစ်ခု token ကိုပိုင်ဆိုင်သောမည်သည့်အကောင့်ကိုစစ်ဆေးရန်ဤ endpoint ကိုအသုံးပြုပါ:

# 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 ကိုခေါ်ဆိုမှုမပြုမီ, လက်ရှိ token ကိုရှိသည်ဘာခွင့်ပြုချက်စစ်ဆေး:

# 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")

တန်ကိန်း သက်တမ်းကုန်ဆုံးမှုကို စောင့်ကြည့်ပါ

သင်၏ token သက်တမ်းကုန်ဆုံးမည်ဆိုပါကစစ်ဆေးပါ:

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:* တစ်ခုအရင်းအမြစ်သို့အပြည့်အဝ access ကိုများအတွက်, သို့မဟုတ် *:* အပြည့်အဝ API ကို access ကိုများအတွက်။

အရင်းအမြစ် ရရှိနိုင်သော လုပ်ဆောင်ချက်များ
servers list, create, update, delete, power, backup, snapshot, resize, exec, *
domains list, search, register, update, renew, *
dns list, create, update, delete, *
snapshots list, delete, *
backups list, restore, *
ssh-keys list, create, delete, *
plans list, *
locations list, *
operating-systems list, *
deployments list, create, delete, *
Manage your tokens: Create, edit, and revoke API tokens at admin.vps.org/account/developers/