[GH-ISSUE #883] rewrite API: /addClient #589

Closed
opened 2026-10-31 20:13:06 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @megoRU on GitHub (Aug 9, 2023).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/883

Are you laughing or high?

{
    "id": 1,
    "settings": "{\"clients\":[{\"id\":\"95e4e7bb-7796-47e7-e8a7-f4055194f776\",\"alterId\":0,\"email\":\"New Client\",\"limitIp\":2,\"totalGB\":42949672960,\"expiryTime\":1682864675944,\"enable\":true,\"tgId\":\"\",\"subId\":\"\"}]}"
}

Do you want to say that it was impossible to do?

{
    "id": 2,
    "settings": {
        "clients": [
            {
                "id": "8a5bce41-e450-4a96-89c0-cc99a6319448",
                "flow": "xtls-rprx-vision",
                "email": "sddakiwz",
                "limitIp": 0,
                "totalGB": 0,
                "expiryTime": 0,
                "enable": true,
                "tgId": "",
                "subId": "1l50k92xrukq8fzt"
            }
        ]
    }
}
Originally created by @megoRU on GitHub (Aug 9, 2023). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/883 Are you laughing or high? ```json { "id": 1, "settings": "{\"clients\":[{\"id\":\"95e4e7bb-7796-47e7-e8a7-f4055194f776\",\"alterId\":0,\"email\":\"New Client\",\"limitIp\":2,\"totalGB\":42949672960,\"expiryTime\":1682864675944,\"enable\":true,\"tgId\":\"\",\"subId\":\"\"}]}" } ``` Do you want to say that it was impossible to do? ```json { "id": 2, "settings": { "clients": [ { "id": "8a5bce41-e450-4a96-89c0-cc99a6319448", "flow": "xtls-rprx-vision", "email": "sddakiwz", "limitIp": 0, "totalGB": 0, "expiryTime": 0, "enable": true, "tgId": "", "subId": "1l50k92xrukq8fzt" } ] } } ```
bsakaguchi 2026-10-31 20:13:06 +07:00
Author
Owner

@AmoAlireza commented on GitHub (Aug 9, 2023):

emmm you don't know how to convert it? :)

simple python and php add client example:

import requests
import random
import string
import uuid
import json

base_url = 'https://DOMAIN:PORT'

# Login 
login_data = {
  'username': 'USER',
  'password': 'PASS'
}

r = requests.post(f'{base_url}/login', data=login_data)

if r.status_code == 200:

  # Save cookies and convert to string
  cookies = r.cookies
  cookie_str = '; '.join([str(x)+"="+str(y) for x,y in cookies.get_dict().items()])

  # Generate random strings
  email = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8))
  subId = ''.join(random.choices(string.ascii_lowercase + string.digits, k=16))
  uuid = str(uuid.uuid4())

  total_gb = int(input("USER Traffic(GB): "))
  total_bytes = total_gb * 1024 * 1024 * 1024

  # Create request body
  data = {
  "id": 1,

  "settings": json.dumps({
    "clients": [
    {
      "id":uuid, 
      "alterId":0,
      "email":email, 
      "totalGB":total_bytes, 
      "expiryTime":-2592000000, 
      "enable":True, 
      "tgId":"", 
      "subId":subId, 
      "limitIp":1, 
      "flow": "xtls-rprx-vision"
      }
    ]
  })
}

  # Make request
  headers = {'Cookie': cookie_str}  
  r = requests.post(f'{base_url}/panel/api/inbounds/addClient', headers=headers, json=data)

  print("\nJSON RESPONSE:",r.text, "\n")

else:
  print("Login failed")

PHP:

<?php

$base_url = 'https://DOMAIN:PORT';

// Login
$login_data = array(
  'username' => 'USER',
  'password' => 'PASS'
);

$r = requests_post($base_url . '/login', $login_data);

if ($r->status_code == 200) {

  // Save cookies and convert to string
  $cookies = $r->cookies;
  $cookie_str = '';
  foreach ($cookies->get_dict() as $x => $y) {
    $cookie_str .= $x . '=' . $y . '; ';
  }

  // Generate random strings
  $email = '';
  $subId = '';
  $uuid = uniqid();

  $total_gb = readline("USER Traffic(GB): ");
  $total_bytes = $total_gb * 1024 * 1024 * 1024;

  // Create request body
  $data = array(
    "id" => 1,
    "settings" => json_encode(array(
      "clients" => array(
        array(
          "id" => $uuid,
          "alterId" => 0,
          "email" => $email,
          "totalGB" => $total_bytes,
          "expiryTime" => -2592000000,
          "enable" => true,
          "tgId" => "",
          "subId" => $subId,
          "limitIp" => 1,
          "flow" => "xtls-rprx-vision"
        )
      )
    ))
  );

  // Make request
  $headers = array('Cookie' => $cookie_str);
  $r = requests_post($base_url . '/panel/api/inbounds/addClient', $headers, $data);

  echo "
JSON RESPONSE:" . $r->text . "
";

} else {
  echo "Login failed";
}

?>
<!-- gh-comment-id:1671178507 --> @AmoAlireza commented on GitHub (Aug 9, 2023): emmm you don't know how to convert it? :) simple python and php add client example: ```python import requests import random import string import uuid import json base_url = 'https://DOMAIN:PORT' # Login login_data = { 'username': 'USER', 'password': 'PASS' } r = requests.post(f'{base_url}/login', data=login_data) if r.status_code == 200: # Save cookies and convert to string cookies = r.cookies cookie_str = '; '.join([str(x)+"="+str(y) for x,y in cookies.get_dict().items()]) # Generate random strings email = ''.join(random.choices(string.ascii_lowercase + string.digits, k=8)) subId = ''.join(random.choices(string.ascii_lowercase + string.digits, k=16)) uuid = str(uuid.uuid4()) total_gb = int(input("USER Traffic(GB): ")) total_bytes = total_gb * 1024 * 1024 * 1024 # Create request body data = { "id": 1, "settings": json.dumps({ "clients": [ { "id":uuid, "alterId":0, "email":email, "totalGB":total_bytes, "expiryTime":-2592000000, "enable":True, "tgId":"", "subId":subId, "limitIp":1, "flow": "xtls-rprx-vision" } ] }) } # Make request headers = {'Cookie': cookie_str} r = requests.post(f'{base_url}/panel/api/inbounds/addClient', headers=headers, json=data) print("\nJSON RESPONSE:",r.text, "\n") else: print("Login failed") ``` PHP: ```php <?php $base_url = 'https://DOMAIN:PORT'; // Login $login_data = array( 'username' => 'USER', 'password' => 'PASS' ); $r = requests_post($base_url . '/login', $login_data); if ($r->status_code == 200) { // Save cookies and convert to string $cookies = $r->cookies; $cookie_str = ''; foreach ($cookies->get_dict() as $x => $y) { $cookie_str .= $x . '=' . $y . '; '; } // Generate random strings $email = ''; $subId = ''; $uuid = uniqid(); $total_gb = readline("USER Traffic(GB): "); $total_bytes = $total_gb * 1024 * 1024 * 1024; // Create request body $data = array( "id" => 1, "settings" => json_encode(array( "clients" => array( array( "id" => $uuid, "alterId" => 0, "email" => $email, "totalGB" => $total_bytes, "expiryTime" => -2592000000, "enable" => true, "tgId" => "", "subId" => $subId, "limitIp" => 1, "flow" => "xtls-rprx-vision" ) ) )) ); // Make request $headers = array('Cookie' => $cookie_str); $r = requests_post($base_url . '/panel/api/inbounds/addClient', $headers, $data); echo " JSON RESPONSE:" . $r->text . " "; } else { echo "Login failed"; } ?> ```
Author
Owner

@megoRU commented on GitHub (Aug 9, 2023):

@AmoAlireza this is understandable, but why not do it immediately without the need to wrap it in a string?

<!-- gh-comment-id:1671222104 --> @megoRU commented on GitHub (Aug 9, 2023): @AmoAlireza this is understandable, but why not do it immediately without the need to wrap it in a string?
Author
Owner

@mehdikhoram commented on GitHub (Aug 24, 2023):

@megoRU
Are you familiar with Go structs and how to convert structs into a JSON string? It's how Golang deals with nested structs and objects, but there was a way around this that wasn't convenient for developers to do all those overheads.

<!-- gh-comment-id:1692222722 --> @mehdikhoram commented on GitHub (Aug 24, 2023): @megoRU Are you familiar with Go structs and how to convert structs into a JSON string? It's how Golang deals with nested structs and objects, but there was a way around this that wasn't convenient for developers to do all those overheads.
Author
Owner

@megoRU commented on GitHub (Aug 24, 2023):

@megoRU Are you familiar with Go structs and how to convert structs into a JSON string? It's how Golang deals with nested structs and objects, but there was a way around this that wasn't convenient for developers to do all those overheads.

I didn't work with Go language

<!-- gh-comment-id:1692237469 --> @megoRU commented on GitHub (Aug 24, 2023): > @megoRU Are you familiar with Go structs and how to convert structs into a JSON string? It's how Golang deals with nested structs and objects, but there was a way around this that wasn't convenient for developers to do all those overheads. I didn't work with Go language
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#589
No description provided.