Skip to content

REST API

Automate V2RayTun with the REST API — manage users, nodes, hosts, and squads programmatically.

Authentication

The API supports two authentication methods:

JWT Token

Obtain a JWT by logging in through the panel or via the login endpoint:

Bash
curl -X POST https://panel.example.com/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": "your-password"}'

The response includes an accessToken. Pass it in subsequent requests:

Bash
curl https://panel.example.com/api/users \
  -H "Authorization: Bearer ACCESS_TOKEN"

API Token

Generate a long-lived API token in Settings → API Tokens. Use it as a Bearer token the same way:

Bash
curl https://panel.example.com/api/users \
  -H "Authorization: Bearer API_TOKEN"

Core Endpoints

Users

MethodEndpointDescription
GET/api/usersList all users
POST/api/usersCreate a new user
GET/api/users/:idGet user details
PUT/api/users/:idUpdate a user
DELETE/api/users/:idDelete a user

Nodes

MethodEndpointDescription
GET/api/nodesList all nodes
POST/api/nodesCreate a new node
GET/api/nodes/:idGet node details
DELETE/api/nodes/:idDelete a node

Hosts

MethodEndpointDescription
GET/api/hostsList all hosts
PUT/api/hosts/:idUpdate a host

Squads

MethodEndpointDescription
GET/api/squadsList all squads
POST/api/squadsCreate a squad
PUT/api/squads/:idUpdate a squad
DELETE/api/squads/:idDelete a squad

Examples

Create a User (JavaScript)

JavaScript
const res = await fetch("https://panel.example.com/api/users", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer API_TOKEN",
  },
  body: JSON.stringify({
    username: "alice",
    trafficLimitGB: 50,
    expiresAt: "2025-12-31T23:59:59Z",
    squadId: 1,
  }),
});
const user = await res.json();
console.log(user.subscriptionUrl);

Create a User (Python)

Python
import requests
 
resp = requests.post(
    "https://panel.example.com/api/users",
    headers={"Authorization": "Bearer API_TOKEN"},
    json={
        "username": "alice",
        "trafficLimitGB": 50,
        "expiresAt": "2025-12-31T23:59:59Z",
        "squadId": 1,
    },
)
print(resp.json()["subscriptionUrl"])

Pagination

List endpoints accept page and limit query parameters:

Bash
curl "https://panel.example.com/api/users?page=1&limit=20" \
  -H "Authorization: Bearer API_TOKEN"

Error Responses

Errors return a JSON object with statusCode and message:

JSON
{
  "statusCode": 404,
  "message": "User not found"
}