### Client API Example Request Source: https://pterodactyl-api-docs.netvpx.com/docs/authentication Example of how to get a list of servers for the authenticated user using a Client API key. ```bash # Get list of servers for the authenticated user curl "https://your-panel.com/api/client" \ -H "Authorization: Bearer ptlc_1234567890abcdef" \ -H "Content-Type: application/json" \ -H "Accept: Application/vnd.pterodactyl.v1+json" ``` -------------------------------- ### Getting Started with the Client API Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client Steps to generate an API key and make your first request. ```APIDOC ## Getting Started 1. **Generate a Client API Key** * Go to `https://your-panel.com/account/api` * Click "Create API Key" * Copy the generated key 2. **Make Your First Request** ```bash curl "https://your-panel.com/api/client" \ -H "Authorization: Bearer YOUR_CLIENT_API_KEY" \ -H "Accept: Application/vnd.pterodactyl.v1+json" ``` 3. **Explore Available Servers** * Use the response to see servers you have access to * Note the server identifiers for subsequent requests ``` -------------------------------- ### Fetch Server Details with Python (Requests) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/servers This Python example uses the `requests` library to get server information. Make sure `requests` is installed (`pip install requests`). ```python import requests server_id = 1 headers = { 'Authorization': 'Bearer ptla_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json' } params = {'include': 'allocations,user,node'} response = requests.get(f'https://your-panel.com/api/application/servers/{server_id}', headers=headers, params=params) print(response.json()) ``` -------------------------------- ### Application API Example Request Source: https://pterodactyl-api-docs.netvpx.com/docs/authentication Example of how to get a list of all users using an Application API key. This requires administrator privileges. ```bash # Get list of all users (admin only) curl "https://your-panel.com/api/application/users" \ -H "Authorization: Bearer ptla_1234567890abcdef" \ -H "Content-Type: application/json" \ -H "Accept: Application/vnd.pterodactyl.v1+json" ``` -------------------------------- ### Fetch Server Details with JavaScript (Axios) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/servers This JavaScript example uses the Axios library to fetch server details. Ensure you have Axios installed (`npm install axios`). ```javascript const axios = require('axios'); const serverId = 1; const response = await axios.get(`https://your-panel.com/api/application/servers/${serverId}`, { headers: { 'Authorization': 'Bearer ptla_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json' }, params: { include: 'allocations,user,node' } }); console.log(response.data); ``` -------------------------------- ### List All Nests Request Examples Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/nests-eggs Examples of how to perform a GET request to list all nests with included eggs across various programming languages. ```cURL curl "https://your-panel.com/api/application/nests?include=eggs" \ -H "Authorization: Bearer ptla_YOUR_API_KEY" \ -H "Accept: Application/vnd.pterodactyl.v1+json" ``` ```JavaScript const axios = require('axios'); const response = await axios.get('https://your-panel.com/api/application/nests', { headers: { 'Authorization': 'Bearer ptla_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json' }, params: { include: 'eggs' } }); console.log(response.data); ``` ```Python import requests headers = { 'Authorization': 'Bearer ptla_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json' } params = {'include': 'eggs'} response = requests.get('https://your-panel.com/api/application/nests', headers=headers, params=params) print(response.json()) ``` ```PHP get('https://your-panel.com/api/application/nests', [ 'headers' => [ 'Authorization' => 'Bearer ptla_YOUR_API_KEY', 'Accept' => 'Application/vnd.pterodactyl.v1+json' ], 'query' => ['include' => 'eggs'] ]); $data = json_decode($response->getBody(), true); print_r($data); ?> ``` ```Go package main import ( "fmt" "io" "net/http" ) func main() { client := &http.Client{} req, _ := http.NewRequest("GET", "https://your-panel.com/api/application/nests?include=eggs", nil) req.Header.Add("Authorization", "Bearer ptla_YOUR_API_KEY") req.Header.Add("Accept", "Application/vnd.pterodactyl.v1+json") resp, _ := client.Do(req) defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) fmt.Println(string(body)) } ``` ```Java import okhttp3.*; public class Main { public static void main(String[] args) throws Exception { OkHttpClient client = new OkHttpClient(); Request request = new Request.Builder() .url("https://your-panel.com/api/application/nests?include=eggs") .addHeader("Authorization", "Bearer ptla_YOUR_API_KEY") .addHeader("Accept", "Application/vnd.pterodactyl.v1+json") .build(); Response response = client.newCall(request).execute(); System.out.println(response.body().string()); } } ``` ```C# using System; using System.Net.Http; using System.Threading.Tasks; class Program { static async Task Main(string[] args) { var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer ptla_YOUR_API_KEY"); client.DefaultRequestHeaders.Add("Accept", "Application/vnd.pterodactyl.v1+json"); var response = await client.GetAsync("https://your-panel.com/api/application/nests?include=eggs"); var content = await response.Content.ReadAsStringAsync(); Console.WriteLine(content); } } ``` ```Ruby require 'net/http' require 'uri' uri = URI('https://your-panel.com/api/application/nests?include=eggs') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri) request['Authorization'] = 'Bearer ptla_YOUR_API_KEY' request['Accept'] = 'Application/vnd.pterodactyl.v1+json' response = http.request(request) puts response.body ``` -------------------------------- ### Get Server Startup Configuration (Node.js) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/servers This Node.js example demonstrates how to fetch server startup configuration using the axios library. It includes setting the necessary authorization and accept headers. ```javascript const axios = require('axios'); const serverId = 'd3aac109'; const response = await axios.get(`https://your-panel.com/api/client/servers/${serverId}/startup`, { headers: { 'Authorization': 'Bearer ptlc_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json', 'Content-Type': 'application/json' } }); console.log('Startup config:', response.data); ``` -------------------------------- ### Fetch Server Activity with C# Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/servers This C# example demonstrates fetching server activity using `HttpClient`. It adds authorization and accept headers to the GET request. ```csharp using System; using System.Net.Http; using System.Threading.Tasks; var serverId = "d3aac109"; var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer ptlc_YOUR_API_KEY"); client.DefaultRequestHeaders.Add("Accept", "Application/vnd.pterodactyl.v1+json"); var response = await client.GetAsync($"https://your-panel.com/api/client/servers/{serverId}/activity"); var content = await response.Content.ReadAsStringAsync(); Console.WriteLine(content); ``` -------------------------------- ### Fetch Account Activity Logs with Python (Requests) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/account This Python example uses the `requests` library to fetch account activity logs. Ensure you have `requests` installed (`pip install requests`) and update the placeholder credentials. ```python import requests headers = { 'Authorization': 'Bearer ptlc_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json', 'Content-Type': 'application/json' } response = requests.get('https://your-panel.com/api/client/account/activity', headers=headers) print('Activity logs:', response.json()) ``` -------------------------------- ### Fetch Servers with C# Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/servers This C# example demonstrates fetching server data using `HttpClient`. It shows how to set default request headers for authorization and content type, and then perform a GET request. ```csharp using System.Net.Http; using System.Threading.Tasks; var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer ptla_YOUR_API_KEY"); client.DefaultRequestHeaders.Add("Accept", "Application/vnd.pterodactyl.v1+json"); var response = await client.GetAsync("https://your-panel.com/api/application/servers?include=user,node&per_page=25"); var content = await response.Content.ReadAsStringAsync(); Console.WriteLine(content); ``` -------------------------------- ### Fetch Server Activity with Java Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/servers This Java example uses the `java.net.http` package to send a GET request for server activity. It configures the request with necessary headers. ```java import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.URI; String serverId = "d3aac109"; HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://your-panel.com/api/client/servers/" + serverId + "/activity")) .header("Authorization", "Bearer ptlc_YOUR_API_KEY") .header("Accept", "Application/vnd.pterodactyl.v1+json") .header("Content-Type", "application/json") .GET() .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); ``` -------------------------------- ### Fetch Server Details with Ruby Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/servers This Ruby example uses the standard `net/http` library to make a GET request for server details. ```ruby require 'net/http' require 'json' server_id = 1 uri = URI("https://your-panel.com/api/application/servers/#{server_id}") uri.query = URI.encode_www_form({include: 'allocations,user,node'}) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri) request['Authorization'] = 'Bearer ptla_YOUR_API_KEY' request['Accept'] = 'Application/vnd.pterodactyl.v1+json' response = http.request(request) puts JSON.parse(response.body) ``` -------------------------------- ### Get User Request Examples Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/users Examples for retrieving a user by ID using various programming languages and tools. All requests require an Authorization header with a Bearer token and the specified Accept header. ```bash curl "https://your-panel.com/api/application/users/1?include=servers" \ -H "Authorization: Bearer ptla_YOUR_API_KEY" \ -H "Accept: Application/vnd.pterodactyl.v1+json" ``` ```javascript const axios = require('axios'); const userId = 1; const response = await axios.get(`https://your-panel.com/api/application/users/${userId}`, { headers: { 'Authorization': 'Bearer ptla_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json' }, params: { include: 'servers' } }); console.log(response.data); ``` ```python import requests user_id = 1 headers = { 'Authorization': 'Bearer ptla_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json' } params = {'include': 'servers'} response = requests.get(f'https://your-panel.com/api/application/users/{user_id}', headers=headers, params=params) print(response.json()) ``` ```php get("https://your-panel.com/api/application/users/{$userId}", [ 'headers' => [ 'Authorization' => 'Bearer ptla_YOUR_API_KEY', 'Accept' => 'Application/vnd.pterodactyl.v1+json' ], 'query' => ['include' => 'servers'] ]); $data = json_decode($response->getBody(), true); print_r($data); ?> ``` ```go package main import ( "encoding/json" "fmt" "net/http" ) func main() { userId := 1 url := fmt.Sprintf("https://your-panel.com/api/application/users/%d?include=servers", userId) client := &http.Client{} req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ptla_YOUR_API_KEY") req.Header.Add("Accept", "Application/vnd.pterodactyl.v1+json") resp, _ := client.Do(req) defer resp.Body.Close() var result map[string]interface{} json.NewDecoder(resp.Body).Decode(&result) fmt.Println(result) } ``` ```java import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.URI; int userId = 1; String url = String.format("https://your-panel.com/api/application/users/%d?include=servers", userId); HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(url)) .header("Authorization", "Bearer ptla_YOUR_API_KEY") .header("Accept", "Application/vnd.pterodactyl.v1+json") .GET() .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); ``` ```csharp using System.Net.Http; using System.Threading.Tasks; var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer ptla_YOUR_API_KEY"); client.DefaultRequestHeaders.Add("Accept", "Application/vnd.pterodactyl.v1+json"); int userId = 1; var response = await client.GetAsync($"https://your-panel.com/api/application/users/{userId}?include=servers"); var content = await response.Content.ReadAsStringAsync(); Console.WriteLine(content); ``` ```ruby require 'net/http' require 'json' user_id = 1 uri = URI("https://your-panel.com/api/application/users/#{user_id}") uri.query = URI.encode_www_form({include: 'servers'}) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri) request['Authorization'] = 'Bearer ptla_YOUR_API_KEY' request['Accept'] = 'Application/vnd.pterodactyl.v1+json' response = http.request(request) puts JSON.parse(response.body) ``` -------------------------------- ### List Server Schedules (C#) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/schedules This C# example uses `HttpClient` to make a GET request for server schedules. It demonstrates adding headers and reading the response content asynchronously. ```csharp using System.Net.Http; using System.Threading.Tasks; var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer ptlc_YOUR_API_KEY"); client.DefaultRequestHeaders.Add("Accept", "Application/vnd.pterodactyl.v1+json"); string serverId = "d3aac109"; var response = await client.GetAsync($"https://your-panel.com/api/client/servers/{serverId}/schedules"); var content = await response.Content.ReadAsStringAsync(); Console.WriteLine("Server schedules: " + content); ``` -------------------------------- ### Copy File Request Examples Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/files Examples of how to perform a file copy operation using various programming languages and tools. ```bash curl -X POST "https://your-panel.com/api/client/servers/d3aac109/files/copy" \ -H "Authorization: Bearer ptlc_YOUR_API_KEY" \ -H "Accept: Application/vnd.pterodactyl.v1+json" \ -H "Content-Type: application/json" \ -d '{ "location": "/config.yml" }' ``` ```javascript const axios = require('axios'); const serverId = 'd3aac109'; const copyData = { location: '/config.yml' }; const response = await axios.post(`https://your-panel.com/api/client/servers/${serverId}/files/copy`, copyData, { headers: { 'Authorization': 'Bearer ptlc_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json', 'Content-Type': 'application/json' } }); console.log('File copied successfully'); ``` ```python import requests server_id = 'd3aac109' headers = { 'Authorization': 'Bearer ptlc_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json', 'Content-Type': 'application/json' } copy_data = { 'location': '/config.yml' } response = requests.post(f'https://your-panel.com/api/client/servers/{server_id}/files/copy', headers=headers, json=copy_data) print('File copied successfully') ``` ```php '/config.yml' ]; $response = $client->post("https://your-panel.com/api/client/servers/{$serverId}/files/copy", [ 'headers' => [ 'Authorization' => 'Bearer ptlc_YOUR_API_KEY', 'Accept' => 'Application/vnd.pterodactyl.v1+json', 'Content-Type' => 'application/json' ], 'json' => $copyData ]); echo "File copied successfully"; ?> ``` ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { serverId := "d3aac109" copyData := map[string]interface{}{ "location": "/config.yml", } jsonData, _ := json.Marshal(copyData) client := &http.Client{} req, _ := http.NewRequest("POST", fmt.Sprintf("https://your-panel.com/api/client/servers/%s/files/copy", serverId), bytes.NewBuffer(jsonData)) req.Header.Add("Authorization", "Bearer ptlc_YOUR_API_KEY") req.Header.Add("Accept", "Application/vnd.pterodactyl.v1+json") req.Header.Add("Content-Type", "application/json") resp, _ := client.Do(req) defer resp.Body.Close() fmt.Println("File copied successfully") } ``` ```java import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.URI; String serverId = "d3aac109"; String jsonData = """ { "location": "/config.yml" } """; HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create("https://your-panel.com/api/client/servers/" + serverId + "/files/copy")) .header("Authorization", "Bearer ptlc_YOUR_API_KEY") .header("Accept", "Application/vnd.pterodactyl.v1+json") .header("Content-Type", "application/json") .POST(HttpRequest.BodyPublishers.ofString(jsonData)) .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println("File copied successfully"); ``` ```csharp using System.Net.Http; using System.Text; using System.Text.Json; using System.Threading.Tasks; var serverId = "d3aac109"; var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer ptlc_YOUR_API_KEY"); client.DefaultRequestHeaders.Add("Accept", "Application/vnd.pterodactyl.v1+json"); var copyData = new { location = "/config.yml" }; var json = JsonSerializer.Serialize(copyData); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = await client.PostAsync($"https://your-panel.com/api/client/servers/{serverId}/files/copy", content); Console.WriteLine("File copied successfully"); ``` ```ruby require 'net/http' require 'json' server_id = 'd3aac109' copy_data = { location: '/config.yml' } uri = URI("https://your-panel.com/api/client/servers/#{server_id}/files/copy") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri) request['Authorization'] = 'Bearer ptlc_YOUR_API_KEY' request['Accept'] = 'Application/vnd.pterodactyl.v1+json' request['Content-Type'] = 'application/json' request.body = copy_data.to_json response = http.request(request) puts "File copied successfully" ``` -------------------------------- ### List Server Databases (Go) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/databases Example using Go to list all databases for a specific server. This snippet demonstrates setting up the HTTP client and request headers. ```go package main import ( "net/http" "io/ioutil" ) func main() { client := &http.Client{} req, _ := http.NewRequest("GET", "https://panel.example.com/api/application/servers/{server}/databases", nil) req.Header.Add("Authorization", "Bearer YOUR_APPLICATION_API_KEY") req.Header.Add("Accept", "application/json") req.Header.Add("Content-Type", "application/json") resp, _ := client.Do(req) defer resp.Body.Close() body, _ := ioutil.ReadAll(resp.Body) } ``` -------------------------------- ### Example Response Structure for Startup Configuration Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/servers This is an example of the JSON response structure when retrieving server startup configuration. It includes details about egg variables and metadata like startup commands and available Docker images. ```json { "object": "list", "data": [ { "object": "egg_variable", "attributes": { "name": "Server Jar File", "description": "The name of the server jarfile to run the server with.", "env_variable": "SERVER_JARFILE", "default_value": "server.jar", "server_value": "server.jar", "is_editable": true, "rules": "required|regex:/^([\w\d._-]+)(\.jar)$/" } }, { "object": "egg_variable", "attributes": { "name": "Server Version", "description": "The version of Minecraft to download and use.", "env_variable": "MINECRAFT_VERSION", "default_value": "latest", "server_value": "1.19.4", "is_editable": true, "rules": "required|string|between:1,20" } } ], "meta": { "startup_command": "java -Xms128M -Xmx{{SERVER_MEMORY}}M -jar {{SERVER_JARFILE}}", "raw_startup_command": "java -Xms128M -Xmx1024M -jar server.jar", "docker_images": { "ghcr.io/pterodactyl/yolks:java_17": "Java 17", "ghcr.io/pterodactyl/yolks:java_11": "Java 11", "ghcr.io/pterodactyl/yolks:java_8": "Java 8" } } } ``` -------------------------------- ### Get User by External ID (Java) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/users Fetch user details using their external ID in Java. This example uses the built-in HttpClient for making the GET request and handling the response. ```java import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.URI; String externalId = "ext-123456"; String url = String.format("https://your-panel.com/api/application/users/external/%s", externalId); HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(url)) .header("Authorization", "Bearer ptla_YOUR_API_KEY") .header("Accept", "Application/vnd.pterodactyl.v1+json") .GET() .build(); HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println(response.body()); ``` -------------------------------- ### Download via CLI Tools Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/backups Examples of downloading the backup file using curl or wget. ```bash # Download using curl curl -L "https://s3.amazonaws.com/backups/..." -o backup.tar.gz # Download using wget wget "https://s3.amazonaws.com/backups/..." -O backup.tar.gz ``` -------------------------------- ### Get Server Backup Details with JavaScript (Fetch API) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/backups This JavaScript example uses the Fetch API to retrieve backup details. It demonstrates how to make a GET request and process the JSON response. ```javascript const serverId = 'd3aac109'; const backupId = 'a4962fe6-90c8-4b89-ba62-a5d3b06426c0'; const response = await fetch(`https://your-panel.com/api/client/servers/${serverId}/backups/${backupId}`, { method: 'GET', headers: { 'Authorization': 'Bearer ptlc_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json', 'Content-Type': 'application/json' } }); const backup = await response.json(); console.log('Backup details:', backup.attributes); console.log(`Status: ${backup.attributes.is_successful ? 'Successful' : 'Failed'}`); console.log(`Size: ${(backup.attributes.bytes / 1024 / 1024).toFixed(2)} MB`); ``` -------------------------------- ### Get 2FA QR Code Request Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/account Request to generate a TOTP QR code for two-factor authentication setup. ```bash curl "https://your-panel.com/api/client/account/two-factor" \ -H "Authorization: Bearer ptlc_YOUR_API_KEY" \ -H "Accept: Application/vnd.pterodactyl.v1+json" \ -H "Content-Type: application/json" ``` -------------------------------- ### Fetch Server Details with C# Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/servers This C# example demonstrates fetching server details asynchronously using `HttpClient`. ```csharp using System.Net.Http; using System.Threading.Tasks; var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer ptla_YOUR_API_KEY"); client.DefaultRequestHeaders.Add("Accept", "Application/vnd.pterodactyl.v1+json"); int serverId = 1; var response = await client.GetAsync($"https://your-panel.com/api/application/servers/{serverId}?include=allocations,user,node"); var content = await response.Content.ReadAsStringAsync(); Console.WriteLine(content); ``` -------------------------------- ### Restore Server Backup using Java Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/backups This Java example demonstrates how to initiate a server backup restore using `java.net.http.HttpClient`. It includes setting up the request, headers, and handling the response. Ensure you have Jackson databind library for JSON processing. ```java import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.URI; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.HashMap; import java.util.Map; public class BackupManager { private static final String API_KEY = "ptlc_YOUR_API_KEY"; private static final String BASE_URL = "https://your-panel.com/api/client"; public void restoreBackup(String serverId, String backupId) throws Exception { String url = BASE_URL + "/servers/" + serverId + "/backups/" + backupId + "/restore"; ``` -------------------------------- ### Get 2FA QR Code Response Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/account Example JSON response containing the QR code image URL and secret key. ```json { "data": { "image_url_data": "otpauth://totp/Pterodactyl:admin%40example.com?secret=XHL4JKY746CH46YJCHA25JWAUDBAM24I&issuer=Pterodactyl", "secret": "XHL4JKY746CH46YJCHA25JWAUDBAM24I" } } ``` -------------------------------- ### Fetch Locations with Python (Requests) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/locations This Python example utilizes the 'requests' library to retrieve location data from the Pterodactyl API. It demonstrates how to set custom headers and query parameters for filtering and pagination. Make sure to install the library (`pip install requests`). ```python import requests headers = { 'Authorization': 'Bearer ptla_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json' } params = { 'include': 'nodes', 'per_page': 25, 'filter[short]': 'us' } response = requests.get('https://your-panel.com/api/application/locations', headers=headers, params=params) print(response.json()) ``` -------------------------------- ### List Server Allocations (Go) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/network Retrieve all network allocations assigned to a server using Go. This example demonstrates setting up the HTTP request with necessary headers. ```go package main import ( "encoding/json" "fmt" "net/http" ) func main() { serverId := "d3aac109" url := fmt.Sprintf("https://your-panel.com/api/client/servers/%s/network/allocations", serverId) client := &http.Client{} req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ptlc_YOUR_API_KEY") req.Header.Add("Accept", "Application/vnd.pterodactyl.v1+json") req.Header.Add("Content-Type", "application/json") resp, _ := client.Do(req) defer resp.Body.Close() var result map[string]interface{} json.NewDecoder(resp.Body).Decode(&result) fmt.Println("Server allocations:", result["data"]) } ``` -------------------------------- ### Connect to MySQL Database Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/databases Examples for establishing a database connection and executing a simple query across different programming languages. ```javascript const mysql = require('mysql2/promise'); async function connectToDatabase() { try { const connection = await mysql.createConnection({ host: 'mysql.example.com', port: 3306, user: 'u4_gKGSzC8x9M', password: 'aP$9gH#x2Kw8', database: 's4_gamedata', charset: 'utf8mb4' }); console.log('Connected successfully!'); // Example query const [rows] = await connection.execute('SELECT COUNT(*) as count FROM players'); console.log(`Player count: ${rows[0].count}`); await connection.end(); } catch (error) { console.error('Connection failed:', error.message); } } connectToDatabase(); ``` ```python import mysql.connector from mysql.connector import Error try { connection = mysql.connector.connect( host='mysql.example.com', port=3306, database='s4_gamedata', user='u4_gKGSzC8x9M', password='aP$9gH#x2Kw8', charset='utf8mb4' ) if connection.is_connected(): print('Connected successfully!') cursor = connection.cursor() cursor.execute("SELECT COUNT(*) as count FROM players") result = cursor.fetchone() print(f"Player count: {result[0]}") except Error as e: print(f"Connection failed: {e}") finally: if connection.is_connected(): cursor.close() connection.close() ``` ```php PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]); echo "Connected successfully!\n"; // Example query $stmt = $pdo->prepare("SELECT COUNT(*) as count FROM players"); $stmt->execute(); $result = $stmt->fetch(); echo "Player count: " . $result['count'] . "\n"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage() . "\n"; } ?> ``` ```java import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; public class DatabaseConnection { public static void main(String[] args) { String url = "jdbc:mysql://mysql.example.com:3306/s4_gamedata?useSSL=false&useUnicode=true&characterEncoding=utf8"; String username = "u4_gKGSzC8x9M"; String password = "aP$9gH#x2Kw8"; try (Connection connection = DriverManager.getConnection(url, username, password)) { System.out.println("Connected successfully!"); // Example query String sql = "SELECT COUNT(*) as count FROM players"; PreparedStatement statement = connection.prepareStatement(sql); ResultSet resultSet = statement.executeQuery(); if (resultSet.next()) { int count = resultSet.getInt("count"); System.out.println("Player count: " + count); } } catch (SQLException e) { System.err.println("Connection failed: " + e.getMessage()); } } } ``` -------------------------------- ### Get WebSocket Token (C#) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/websocket This C# example uses HttpClient to retrieve a WebSocket token and URL. It deserializes the JSON response into strongly-typed objects. ```csharp using System.Net.Http; using System.Text.Json; using System.Threading.Tasks; public class WebSocketData { public string token { get; set; } public string socket { get; set; } } public class WebSocketResponse { public WebSocketData data { get; set; } } var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer ptlc_YOUR_CLIENT_API_KEY"); client.DefaultRequestHeaders.Add("Accept", "Application/vnd.pterodactyl.v1+json"); string serverId = "d3aac109"; var response = await client.GetAsync($"https://your-panel.com/api/client/servers/{serverId}/websocket"); var content = await response.Content.ReadAsStringAsync(); var wsResponse = JsonSerializer.Deserialize(content); Console.WriteLine($"WebSocket URL: {wsResponse.data.socket}"); Console.WriteLine($"JWT Token: {wsResponse.data.token}"); ``` -------------------------------- ### List Users with Servers (Go) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/users This Go program demonstrates how to make an HTTP GET request to list users and include server information. It handles the response and prints the JSON data. ```go package main import ( "encoding/json" "fmt" "net/http" ) func main() { client := &http.Client{} req, _ := http.NewRequest("GET", "https://your-panel.com/api/application/users?include=servers&per_page=25", nil) req.Header.Add("Authorization", "Bearer ptla_YOUR_API_KEY") req.Header.Add("Accept", "Application/vnd.pterodactyl.v1+json") resp, _ := client.Do(req) defer resp.Body.Close() var result map[string]interface{} json.NewDecoder(resp.Body).Decode(&result) fmt.Println(result) } ``` -------------------------------- ### Fetch Server Details with Go Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/servers This Go program demonstrates how to make an HTTP GET request to retrieve server details. ```go package main import ( "encoding/json" "fmt" "net/http" ) func main() { serverId := 1 url := fmt.Sprintf("https://your-panel.com/api/application/servers/%d?include=allocations,user,node", serverId) client := &http.Client{} req, _ := http.NewRequest("GET", url, nil) req.Header.Add("Authorization", "Bearer ptla_YOUR_API_KEY") req.Header.Add("Accept", "Application/vnd.pterodactyl.v1+json") resp, _ := client.Do(req) defer resp.Body.Close() var result map[string]interface{} json.NewDecoder(resp.Body).Decode(&result) fmt.Println(result) } ``` -------------------------------- ### Create Server Database (Ruby) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/databases Use Ruby's Net::HTTP library to create a server database. This example shows setting up the POST request, headers, and JSON body. ```ruby require 'net/http' require 'json' uri = URI('https://panel.example.com/api/application/servers/{server}/databases') http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri) request['Authorization'] = 'Bearer YOUR_APPLICATION_API_KEY' request['Accept'] = 'application/json' request['Content-Type'] = 'application/json' request.body = { database: 'my_database', remote: '%', host: 1 }.to_json response = http.request(request) database = JSON.parse(response.body) ``` -------------------------------- ### List SSH Keys (C#) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/account Use C# and HttpClient to fetch your SSH keys. This example demonstrates adding authorization and accept headers to the GET request. ```csharp using System.Net.Http; using System.Threading.Tasks; var client = new HttpClient(); client.DefaultRequestHeaders.Add("Authorization", "Bearer ptlc_YOUR_API_KEY"); client.DefaultRequestHeaders.Add("Accept", "Application/vnd.pterodactyl.v1+json"); var response = await client.GetAsync("https://your-panel.com/api/client/account/ssh-keys"); var content = await response.Content.ReadAsStringAsync(); Console.WriteLine("SSH keys: " + content); ``` -------------------------------- ### Create User with Go Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/users This Go program shows how to make an HTTP POST request to create a user. It includes JSON marshaling for the request body and setting necessary headers. ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { userData := map[string]interface{}{ "email": "newuser@example.com", "username": "newuser", "first_name": "New", "last_name": "User", "password": "secure_password_123", "language": "en", "root_admin": false, } jsonData, _ := json.Marshal(userData) client := &http.Client{} req, _ := http.NewRequest("POST", "https://your-panel.com/api/application/users", bytes.NewBuffer(jsonData)) req.Header.Add("Authorization", "Bearer ptla_YOUR_API_KEY") req.Header.Add("Accept", "Application/vnd.pterodactyl.v1+json") req.Header.Add("Content-Type", "application/json") resp, _ := client.Do(req) defer resp.Body.Close() var result map[string]interface{} json.NewDecoder(resp.Body).Decode(&result) fmt.Println(result) } ``` -------------------------------- ### Suspend Server using PHP (Guzzle) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/servers This PHP example uses the Guzzle HTTP client to suspend a server. Ensure Guzzle is installed via Composer. ```php post("https://your-panel.com/api/application/servers/{$serverId}/suspend", [ 'headers' => [ 'Authorization' => 'Bearer ptla_YOUR_API_KEY', 'Accept' => 'Application/vnd.pterodactyl.v1+json' ] ]); echo 'Server suspended successfully'; ?> ``` -------------------------------- ### Clone and Set Up Pterodactyl API Docs Locally Source: https://pterodactyl-api-docs.netvpx.com/docs/contributing Steps to fork, clone, install dependencies, and start the development server for the Pterodactyl API documentation project. ```bash # 1. Fork and clone the repository git clone https://github.com/YOUR_USERNAME/pterodactyl-api-docs.git cd pterodactyl-api-docs # 2. Install dependencies npm install # 3. Create a feature branch git checkout -b feature/your-improvement # 4. Start development server npm start # 5. Make your changes and test # The site will be available at http://localhost:3000 # 6. Build to test for errors npm run build # 7. Commit and push your changes git add . git commit -m "feat: improve authentication examples" git push origin feature/your-improvement # 8. Create a pull request on GitHub ``` -------------------------------- ### Restore Server Backup using Go Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/backups This Go program demonstrates how to initiate a server backup restore using the standard `net/http` package. It handles JSON marshaling, request creation, and response status checking. ```go package main import ( "bytes" "encoding/json" "fmt" "net/http" ) func main() { serverId := "d3aac109" backupId := "a4962fe6-90c8-4b89-ba62-a5d3b06426c0" url := fmt.Sprintf("https://your-panel.com/api/client/servers/%s/backups/%s/restore", serverId, backupId) restoreData := map[string]interface{}{ "truncate": true, // Delete existing files before restore } jsonData, _ := json.Marshal(restoreData) client := &http.Client{} req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData)) req.Header.Add("Authorization", "Bearer ptlc_YOUR_API_KEY") req.Header.Add("Accept", "Application/vnd.pterodactyl.v1+json") req.Header.Add("Content-Type", "application/json") resp, err := client.Do(req) if err != nil { fmt.Printf("Error: %v\n", err) return } defer resp.Body.Close() if resp.StatusCode == 202 { fmt.Println("Backup restoration initiated") fmt.Println("Server will be restored from backup - this may take several minutes") } else { fmt.Printf("Failed to initiate restore: %d\n", resp.StatusCode) } } ``` -------------------------------- ### Fetch Locations with JavaScript (Axios) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/locations This JavaScript snippet uses the Axios library to make a GET request to the Pterodactyl API for locations. It includes parameters for including nodes, setting results per page, and filtering by a short location code. Ensure you have Axios installed (`npm install axios`). ```javascript const axios = require('axios'); const response = await axios.get('https://your-panel.com/api/application/locations', { headers: { 'Authorization': 'Bearer ptla_YOUR_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json' }, params: { include: 'nodes', per_page: 25, 'filter[short]': 'us' } }); console.log(response.data); ``` -------------------------------- ### Example File Response Source: https://pterodactyl-api-docs.netvpx.com/docs/api/client/files The expected plain text response format when reading a configuration file. ```text # Minecraft server properties server-port=25565 gamemode=survival max-players=20 online-mode=true difficulty=normal spawn-protection=16 white-list=false generate-structures=true allow-flight=false ``` -------------------------------- ### Create Server Database (Go) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/application/databases This Go program demonstrates creating a server database using the standard net/http package. It marshals data to JSON and sets required headers. ```go package main import ( "bytes" "encoding/json" "net/http" ) func main() { data := map[string]interface{}{ "database": "my_database", "remote": "%", "host": 1, } jsonData, _ := json.Marshal(data) client := &http.Client{} req, _ := http.NewRequest("POST", "https://panel.example.com/api/application/servers/{server}/databases", bytes.NewBuffer(jsonData)) req.Header.Add("Authorization", "Bearer YOUR_APPLICATION_API_KEY") req.Header.Add("Accept", "application/json") req.Header.Add("Content-Type", "application/json") resp, _ := client.Do(req) defer resp.Body.Close() } ``` -------------------------------- ### Get WebSocket Token (JavaScript) Source: https://pterodactyl-api-docs.netvpx.com/docs/api/websocket This JavaScript example uses Axios to request a WebSocket token and URL. The response contains the JWT token and the WebSocket connection endpoint. ```javascript const axios = require('axios'); const serverId = 'd3aac109'; const response = await axios.get(`https://your-panel.com/api/client/servers/${serverId}/websocket`, { headers: { 'Authorization': 'Bearer ptlc_YOUR_CLIENT_API_KEY', 'Accept': 'Application/vnd.pterodactyl.v1+json' } }); const { token, socket } = response.data.data; console.log('WebSocket URL:', socket); console.log('JWT Token:', token); ```