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:
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:
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:
curl https://panel.example.com/api/users \
-H "Authorization: Bearer API_TOKEN"Core Endpoints
Users
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/users | List all users |
| POST | /api/users | Create a new user |
| GET | /api/users/:id | Get user details |
| PUT | /api/users/:id | Update a user |
| DELETE | /api/users/:id | Delete a user |
Nodes
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/nodes | List all nodes |
| POST | /api/nodes | Create a new node |
| GET | /api/nodes/:id | Get node details |
| DELETE | /api/nodes/:id | Delete a node |
Hosts
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/hosts | List all hosts |
| PUT | /api/hosts/:id | Update a host |
Squads
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/squads | List all squads |
| POST | /api/squads | Create a squad |
| PUT | /api/squads/:id | Update a squad |
| DELETE | /api/squads/:id | Delete a squad |
Examples
Create a User (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)
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:
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:
{
"statusCode": 404,
"message": "User not found"
}