YamanVM API

How-To Guide

Start from Zero

A practical onboarding guide for developers who want to integrate YamanVM Public API from scratch.

This page is not only an endpoint reference. It explains integration order, required headers, the task-based flow, and shows the same ideas in PHP, Node.js, and Python.

Core Model

The public API uses token authentication. Read operations return data directly; heavier operations return tasks.

Required Headers

Use `Authorization: Bearer ...` for auth. Mutating requests also require `Idempotency-Key`.

Tracking Model

After provision, format or snapshot calls, track progress from task endpoints.

Download Ready-to-Use Assets

If you do not want to copy code blocks manually, download the prepared client files and Postman collection directly.

1. Recommended Integration Order

Get a token.

Create an API client from the admin panel. The token is only shown in plain text once.

Set the base URL.

For this installation the base URL is currently `https://denemevm.yamanhosting.com`. Because the API prefix is `/api/v1`, the ping endpoint becomes `https://denemevm.yamanhosting.com/api/v1/ping`.

Validate with ping first.

Use `GET /api/v1/ping` as the first live request. Solve auth, header and networking issues here first.

List servers.

Use `GET /api/v1/servers` as the first real data-read flow. Then continue with `GET /api/v1/servers/{server}` and task endpoints as needed.

Use idempotency on mutating operations.

Send `Idempotency-Key` on provision, format, power and snapshot requests. This prevents the same operation from running twice during timeouts or retries.

Important: Heavy operations such as provision and format do not finish synchronously. The API returns a task record. Track the result with `GET /api/v1/tasks/{id}` or `GET /api/v1/servers/{server}/tasks`.

2. What Every Request Should Include

Authentication

Authorization: Bearer yvm_live_xxxxxxxxx

Request ID

X-Request-Id: ext-req-1001

Useful for support and log tracing. It is also returned in the response.

Idempotency

Idempotency-Key: order-1001-format

Required only on mutating requests.

3. PHP How-To

This section is written for developers who already know PHP but need guidance on integrating the API. You can start with raw `curl` and later move to a client such as Guzzle.

Download PHP SDK class

3.1 Ortak istek yardımcı fonksiyonu

<?php
function yamanvmRequest(
    string $method,
    string $path,
    string $token,
    ?array $payload = null,
    ?string $idempotencyKey = null
): array {
    $baseUrl = 'https://yamanvm.yamanhosting.com';
    $headers = [
        'Authorization: Bearer ' . $token,
        'Accept: application/json',
        'X-Request-Id: php-' . uniqid(),
    ];

    if ($idempotencyKey !== null) {
        $headers[] = 'Idempotency-Key: ' . $idempotencyKey;
    }

    if ($payload !== null) {
        $headers[] = 'Content-Type: application/json';
    }

    $ch = curl_init(rtrim($baseUrl, '/') . $path);
    curl_setopt_array($ch, [
        CURLOPT_CUSTOMREQUEST => strtoupper($method),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_TIMEOUT => 30,
    ]);

    if ($payload !== null) {
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload, JSON_UNESCAPED_SLASHES));
    }

    $raw = curl_exec($ch);
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    if ($raw === false) {
        throw new RuntimeException('Curl error: ' . curl_error($ch));
    }

    curl_close($ch);

    return [
        'status' => $status,
        'body' => json_decode($raw, true),
        'raw' => $raw,
    ];
}

3.2 Ping ile auth testi

<?php
$token = 'yvm_live_xxxxxxxxxxxxxxxxx';
$result = yamanvmRequest('GET', '/api/v1/ping', $token);

if ($result['status'] !== 200) {
    print_r($result['body']);
    exit('Ping failed');
}

print_r($result['body']);

3.3 Sunucu listeleme

<?php
$token = 'yvm_live_xxxxxxxxxxxxxxxxx';
$result = yamanvmRequest('GET', '/api/v1/servers?per_page=10', $token);

foreach (($result['body']['servers'] ?? []) as $server) {
    echo $server['id'] . ' - ' . $server['name'] . PHP_EOL;
}

3.4 Task takip etme

<?php
$token = 'yvm_live_xxxxxxxxxxxxxxxxx';
$serverId = 3;

$result = yamanvmRequest('GET', "/api/v1/servers/{$serverId}/tasks", $token);

foreach (($result['body']['tasks'] ?? []) as $task) {
    echo sprintf(
        "#%d %s %s %d%%\n",
        $task['id'],
        $task['type'],
        $task['status'],
        $task['progress_percent']
    );
}

3.5 Power aksiyonu çalıştırma

<?php
$token = 'yvm_live_xxxxxxxxxxxxxxxxx';
$serverId = 3;

$result = yamanvmRequest(
    'POST',
    "/api/v1/servers/{$serverId}/power",
    $token,
    ['action' => 'restart'],
    'srv-3-restart-1001'
);

print_r($result['body']);

3.6 Provision request gönderme

<?php
$token = 'yvm_live_xxxxxxxxxxxxxxxxx';

$payload = [
    'template_id' => 7,
    'host_id' => 2,
    'disk_id' => 4,
    'cpu_count' => 2,
    'ram_gb' => 4,
    'disk_gb' => 80,
    'ip_count' => 1,
    'ip_pool_id' => 1,
    'snapshot_limit' => 3,
];

$result = yamanvmRequest(
    'POST',
    '/api/v1/provisioning/requests',
    $token,
    $payload,
    'order-1001-provision'
);

print_r($result['body']);

// Sonraki adım:
// response içindeki server.id veya task bilgisiyle takip akışına geçin.

4. Node.js How-To

Download Node.js SDK class

4.1 Basit yardımcı fonksiyon

const baseUrl = 'https://yamanvm.yamanhosting.com';
const token = 'yvm_live_xxxxxxxxxxxxxxxxx';

async function yamanvmRequest(method, path, payload = null, idempotencyKey = null) {
  const headers = {
    Authorization: `Bearer ${token}`,
    Accept: 'application/json',
    'X-Request-Id': `node-${Date.now()}`,
  };

  if (idempotencyKey) {
    headers['Idempotency-Key'] = idempotencyKey;
  }

  if (payload) {
    headers['Content-Type'] = 'application/json';
  }

  const response = await fetch(`${baseUrl}${path}`, {
    method,
    headers,
    body: payload ? JSON.stringify(payload) : undefined,
  });

  return {
    status: response.status,
    body: await response.json(),
  };
}

4.2 Ping

const ping = await yamanvmRequest('GET', '/api/v1/ping');
console.log(ping.status, ping.body);

4.3 Format task başlatma

const formatResponse = await yamanvmRequest(
  'POST',
  '/api/v1/servers/3/format',
  {
    template_id: 7,
    admin_password: 'NewPass!123',
    confirm_reset: true,
  },
  'srv-3-format-1001'
);

console.log(formatResponse.status, formatResponse.body);

5. Python How-To

Download Python SDK class

5.1 Requests ile temel istemci

import time
import requests

BASE_URL = "https://yamanvm.yamanhosting.com"
TOKEN = "yvm_live_xxxxxxxxxxxxxxxxx"

def yamanvm_request(method, path, payload=None, idempotency_key=None):
    headers = {
        "Authorization": f"Bearer {TOKEN}",
        "Accept": "application/json",
        "X-Request-Id": f"python-{int(time.time())}",
    }

    if idempotency_key:
        headers["Idempotency-Key"] = idempotency_key

    response = requests.request(
        method,
        f"{BASE_URL}{path}",
        json=payload,
        headers=headers,
        timeout=30,
    )

    return response.status_code, response.json()

5.2 Sunucu görevlerini çekme

status, body = yamanvm_request("GET", "/api/v1/servers/3/tasks")
print(status)
print(body)

5.3 Snapshot oluşturma

status, body = yamanvm_request(
    "POST",
    "/api/v1/servers/3/snapshots",
    {
        "name": "release-before-upgrade",
        "description": "Checkpoint before upgrade",
    },
    "srv-3-snapshot-1001",
)

print(status)
print(body)

6. Reading Errors and Retry Strategy

401

The token is missing or invalid. Fix authentication first.

403

The token is valid but the required scope is missing, or IP restriction is active.

422

The payload violates validation or business rules. Check the `errors` field.

If you need to retry, send the same operation with the same `Idempotency-Key`. If you generate a new key, the system treats it as a new operation.