VPS.org API

ឯកសារ REST API

API គណនី

យក​ទម្រង់​គណនី និង​ព័ត៌មាន​តួអក្សរ API & # 160; ។ មាន​ប្រយោជន៍​សម្រាប់​កំណត់​អត្តសញ្ញាណ​គណនី និង​សិទ្ធិ​ដែល​បាន​ភ្ជាប់​ជាមួយ​តួអក្សរ API & # 160; ។

ចំណុចបញ្ចប់ ចំណុច​បញ្ចប់​ ១
ផ្លូវមូលដ្ឋាន /api/v1/account
ទទួលបាន /api/v1/account/me/

យក​ព័ត៌មាន​គណនី និង​តួអក្សរ​និមិត្ត​សញ្ញា

ត្រឡប់​ទិន្នន័យ​មេតា​ទម្រង់​គណនី និង​វិសាលភាព​តួអក្សរ​/ សិទ្ធិ​សម្រាប់​តួអក្សរ API ដែល​បាន​ប្រើ​ក្នុង​សំណើ & # 160; ។ វា​មាន​ប្រយោជន៍​នៅពេល​ដែល​អ្នក​គ្រប់គ្រង​តួអក្សរ API ច្រើន និង​ត្រូវការ​កំណត់​អត្តសញ្ញាណ​គណនី​ដែល​តួអក្សរ​ជា​កម្មសិទ្ធិ និង​សិទ្ធិ​ដែល​វា​មាន & # 160; ។

ការផ្ទៀងផ្ទាត់ភាពត្រឹមត្រូវ

ត្រូវការ​តួអក្សរ​សម្គាល់ API ដែល​ត្រឹមត្រូវ & # 160; ។ តួអក្សរ​សម្គាល់​សកម្ម​ណាមួយ​អាច​ចូលដំណើរការ​ចំណុច​បញ្ចប់​នេះ​ដោយ​មិន​គិត​ពី​វិសាលភាព​សិទ្ធិ​របស់​វា & # 160; ។

សំណើឧទាហរណ៍

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 លើ​កម្មវិធី​ផ្សេងគ្នា ប្រើ​ចំណុច​បញ្ចប់​នេះ​ដើម្បី​ផ្ទៀងផ្ទាត់​គណនី​ដែល​តួអក្សរ​ជា​របស់​វា & # 160; ៖

# 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 ពិនិត្យ​មើល​ថាតើ​មាន​សិទ្ធិ​អ្វី​ដែល​តួអក្សរ​បច្ចុប្បន្ន​មាន & # 160; ៖

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

ត្រួតពិនិត្យ​ការ​ផុត​កំណត់​របស់​តួអក្សរ​និមិត្ត​សញ្ញា

ពិនិត្យ​មើល​ថាតើ​តួអក្សរ​និមិត្ត​សញ្ញា​របស់​អ្នក​នឹង​ផុត​កំណត់​ឬ​ទេ & # 160; ៖

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 & # 160; ។

ធនធាន សកម្មភាព​ដែល​មាន
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/