Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Add API #51

Merged
merged 1 commit into from
Nov 15, 2022
Merged

Add API #51

merged 1 commit into from
Nov 15, 2022

Conversation

hossinasaadi
Copy link
Owner

Postman collection attached

X-UI API.postman_collection3.zip

@hossinasaadi hossinasaadi added the enhancement New feature or request label Nov 15, 2022
@hossinasaadi hossinasaadi merged commit 845409f into main Nov 15, 2022
@amihos
Copy link

amihos commented Nov 17, 2022

This is awesome. Is it done? How to use it? Will you please provide documentation?

@hossinasaadi
Copy link
Owner Author

@amihos yes it’s done, install postman and open attached json collection

@rezafarokhi
Copy link

You've done a great work. Tanx a lot

@rezafarokhi
Copy link

rezafarokhi commented Nov 18, 2022

Hi There,
when i use my domain name for API, In browser it returns json format and it's correct but when i use it in postman it just returns html format and content-type value in postman is html while in browser it's in right format (json)!

cause i use cdn i change the settings in cdn panel and but it didn't change the output format for postman and again it returns html in postman.

did you parse json in your code? or it is about cdn?

@hossinasaadi
Copy link
Owner Author

Hi There, when i use my domain name for API, In browser it returns json format and it's correct but when i use it in postman it just returns html format and content-type value in postman is html while in browser it's in right format (json)!

cause i use cdn i change the settings in cdn panel and but it didn't change the output format for postman and again it returns html in postman.

did you parse json in your code? or it is about cdn?

Hi @rezafarokhi , it’s about cdn, but you can convert from string anyway.

@amihos
Copy link

amihos commented Nov 18, 2022

Hi @hossinasaadi

I am having the same experience. Beside postman that shows html, I also tried Google script FetchURl Class which is for calling apis and the result was the same: HTML. The only way to see the correct Json output is to call the link via browser. Also, I noticed that the HTML does not contain JSON data.

Here is the output:

<style> [v-cloak] { display: none; } </style> <title>登录</title> <style> #app { padding-top: 100px; } h1 { text-align: center; color: #fff; margin: 20px 0 50px 0; } .ant-btn, .ant-input { height: 50px; border-radius: 30px; } .ant-input-affix-wrapper .ant-input-prefix { left: 23px; } .ant-input-affix-wrapper .ant-input:not(:first-child) { padding-left: 50px; } .selectLang{ display: flex; text-align: center; justify-content: center; } </style>

登录

登录
                        <a-row justify="center" class="selectLang">
                            <a-col :span="4"><span>Language : </span></a-col>

                            <a-col :span="6">
                                <a-select
                                        ref="selectLang"
                                        v-model="lang"
                                        @change="setLang(lang)"
                                >
                                    <a-select-option  :value="l.value" label="China" v-for="l in supportLangs" >
                                        <span role="img" aria-label="l.name" v-text="l.icon"></span>
                                        &nbsp;&nbsp;<span v-text="l.name"></span>
                                    </a-select-option>
                                </a-select>
                            </a-col>

                        </a-row>



                    </a-form-item>
                </a-form>
            </a-col>
        </a-row>
    </a-layout-content>
</transition>
<script src="/assets/vue@2.6.12/vue.min.js"></script> <script src="/assets/moment/moment.min.js"></script> <script src="/assets/ant-design-vue@1.7.2/antd.min.js"></script> <script src="/assets/base64/base64.min.js"></script> <script src="/assets/axios/axios.min.js"></script> <script src="/assets/qs/qs.min.js"></script> <script src="/assets/qrcode/qrious.min.js"></script> <script src="/assets/clipboard/clipboard.min.js"></script> <script src="/assets/uri/URI.min.js"></script> <script src="/assets/js/axios-init.js?0.4.9"></script> <script src="/assets/js/util/common.js?0.4.9"></script> <script src="/assets/js/util/date-util.js?0.4.9"></script> <script src="/assets/js/util/utils.js?0.4.9"></script> <script src="/assets/js/model/xray.js?0.4.9"></script> <script src="/assets/js/model/models.js?0.4.9"></script> <script src="/assets/js/langs.js"></script> <script> const basePath = '\/'; axios.defaults.baseURL = basePath; </script> <script> const leftColor = RandomUtil.randomIntRange(0x222222, 0xFFFFFF / 2).toString(16); const rightColor = RandomUtil.randomIntRange(0xFFFFFF / 2, 0xDDDDDD).toString(16); const deg = RandomUtil.randomIntRange(0, 360); const background = `linear-gradient(${deg}deg, #${leftColor} 10%, #${rightColor} 100%)`; document.querySelector('#app').style.background = background; const app = new Vue({ delimiters: ['[[', ']]'], el: '#app', data: { loading: false, user: new User(), lang : "" }, created(){ this.lang = getLang(); }, methods: { async login() { this.loading = true; const msg = await HttpUtil.post('/login', this.user); this.loading = false; if (msg.success) { location.href = basePath + 'xui/'; } } } }); </script>

@amihos
Copy link

amihos commented Nov 19, 2022

Update: I fixed the issue by calling login request first, getting cookie and use it in headers for getting inbounds call and it worked

@rezafarokhi
Copy link

Update: I fixed the issue by calling login request first, getting cookie and use it in headers for getting inbounds call and it worked

How did you call login request?

@amihos
Copy link

amihos commented Nov 19, 2022

Update: I fixed the issue by calling login request first, getting cookie and use it in headers for getting inbounds call and it worked

How did you call login request?

Just Call like this:
https://domain/login?username=yourusername&password=yourpassword

use thisheader in your request:

"headers": {
"accept": "application/json, text/plain, /",
"content-type": "application/x-www-form-urlencoded; charset=UTF-8"
},
"method": "POST",
"mode": "cors",
"credentials": "include" }

@Danaserver
Copy link

Update: I fixed the issue by calling login request first, getting cookie and use it in headers for getting inbounds call and it worked

How did you call login request?

HOw

Update: I fixed the issue by calling login request first, getting cookie and use it in headers for getting inbounds call and it worked

لاگین کردم و {"success":true,"msg":"登录成功","obj":null} دریافت شد
کوکی هم دریافت شد به همراه session
برای get inbound فقط [Temporary Redirect] میده
curl_setopt_array($curl, array(
CURLOPT_URL => "http://127.0.0.1:54321/xui/API/inbounds/get/9",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER =>$cookies['session']
));

@Danaserver
Copy link

وقت بخیر
امکان اینکه یک سمپل با CURL برای PHP بذارید هست؟

@Danaserver
Copy link

وقت بخیر امکان اینکه یک سمپل با CURL برای PHP بذارید هست؟
انجام شد
curl_setopt($curl2, CURLOPT_HTTPHEADER, array("Cookie: session=".$cookies['session']));

@LordDeveloper
Copy link

LordDeveloper commented Nov 23, 2022

Hi, When we use the Rest API to get the information of an inbound, it returns null in clientStats object. Is there a specific reason?

@LordDeveloper
Copy link

LordDeveloper commented Nov 23, 2022

Also needed some routes:

  1. Getting a specific client details:
    /inbounds/:inboundId/clients/:clientId
    or
    /clients/:id

  2. Delete a inbound specific client:
    /inbounds/:inboundId/clients/delete/:id
    or
    /clients/delete/:id

  3. Updating a inbound specific client [POST]:
    /inbounds/clients/update/:id (payload)
    or
    /cliends/update/:id (payload)

  4. Creating a client for a inbound[POST]:
    /inbounds/:id/clients/create (payload)

  5. Getting a specific inbound clientStats:
    /inbounds/:id/clients

I think this will be very easy for you
:)

@LordDeveloper
Copy link

Heeyy any body is here?

@LordDeveloper
Copy link

@hossinasaadi

1 similar comment
@LordDeveloper
Copy link

@hossinasaadi

@hossinasaadi
Copy link
Owner Author

@hossinasaadi

Why you mention repeatedly?
if anyone can add these routes will add.
also you can say it as request no and order!

@LordDeveloper
Copy link

Because it is necessary. If you do it for a fee, I can contact you on Telegram.

@mehdikhody
Copy link

#137

@SatanicDeveloper
Copy link

生成 xray 配置文件失败: json: error calling MarshalJSON for type json_util.RawMessage: invalid character '"' after object key:value pair
used rest api but pannel stopped. I think there was a problem with my json request body.
how to fix this??

@LordDeveloper
Copy link

生成 xray 配置文件失败: json: error calling MarshalJSON for type json_util.RawMessage: invalid character '"' after object key:value pair used rest api but pannel stopped. I think there was a problem with my json request body. how to fix this??

Go language logic :)

@mmiladkdr
Copy link

mmiladkdr commented Nov 28, 2022

سلام
بعد از اضافه کردن کاربرا با استفاده از وب سرویس xray با خطا مواجه میشه و دیگه کار نمیکنه
راهی هست بشه متوجه شد که چرا بعد از اضافه کردن کاربران سیستم با خطا مواجه میشه ؟
یوزر به طور کامل و صحیح ایجاد میشه و ارسال میشه و در پنل با کلیه مشخصات وارد شده فعال میشه

1414

نمونه درخواست برای ایجاد کاربر:

{"up":0,"down":0,"total":96636764160,"remark":"Mirzaei","enable":true,"expiryTime":1674061858000,"listen":null,"port":5129,"protocol":"vmess","settings":"{"clients":[{"id":"df5001e7-080c-3603-bf56-0fbc26cf741f","email":"5129xxx@xxx.xxx","alterId":0,"limitIp":1,"totalGB":0,"expiryTime":""},{"id":"d2a818df-51df-3377-95f5-18d210ceaf6f","email":"5129xxxxx@xxxx.xxx","alterId":0,"limitIp":1,"totalGB":0,"expiryTime":""}],"disableInsecureEncryption":false}","streamSettings":"{"network":"ws","security":"none","wsSettings":{"acceptProxyProtocol":false,"path":"\/","headers":[]}}","sniffing":"{"enabled":true,"destOverride":["http","tls"]}"}

اشتراک ایجاد شده

1313

جیسون اشتراک

{ "v": "2", "ps": "Mirzaei", "add": "xxxxxxxxxxx", "port": 4129, "id": "33c36149-ffe9-3474-948f-e932e067c703", "aid": 0, "net": "ws", "type": "none", "host": "", "path": "/", "tls": "none" }

حتی سرویس رو ریست کردم چند بار نصب کردم ولی هر باز بعد از ایجاد اشتراک xray با خطا مواجه میشه و کار نمیکنه هیچی
!!!!

@theMeysam
Copy link

Postman collection attached

X-UI API.postman_collection3.zip

Could you probably improve API to "settings", "streamSettings" and "sniffing" return object not string?

@rezafarokhi
Copy link

سلام بعد از اضافه کردن کاربرا با استفاده از وب سرویس xray با خطا مواجه میشه و دیگه کار نمیکنه راهی هست بشه متوجه شد که چرا بعد از اضافه کردن کاربران سیستم با خطا مواجه میشه ؟ یوزر به طور کامل و صحیح ایجاد میشه و ارسال میشه و در پنل با کلیه مشخصات وارد شده فعال میشه

1414

نمونه درخواست برای ایجاد کاربر:

{"up":0,"down":0,"total":96636764160,"remark":"Mirzaei","enable":true,"expiryTime":1674061858000,"listen":null,"port":5129,"protocol":"vmess","settings":"{"clients":[{"id":"df5001e7-080c-3603-bf56-0fbc26cf741f","email":"5129xxx@xxx.xxx","alterId":0,"limitIp":1,"totalGB":0,"expiryTime":""},{"id":"d2a818df-51df-3377-95f5-18d210ceaf6f","email":"5129xxxxx@xxxx.xxx","alterId":0,"limitIp":1,"totalGB":0,"expiryTime":""}],"disableInsecureEncryption":false}","streamSettings":"{"network":"ws","security":"none","wsSettings":{"acceptProxyProtocol":false,"path":"/","headers":[]}}","sniffing":"{"enabled":true,"destOverride":["http","tls"]}"}

اشتراک ایجاد شده

1313

جیسون اشتراک

{ "v": "2", "ps": "Mirzaei", "add": "xxxxxxxxxxx", "port": 4129, "id": "33c36149-ffe9-3474-948f-e932e067c703", "aid": 0, "net": "ws", "type": "none", "host": "", "path": "/", "tls": "none" }

حتی سرویس رو ریست کردم چند بار نصب کردم ولی هر باز بعد از ایجاد اشتراک xray با خطا مواجه میشه و کار نمیکنه هیچی !!!!

اگر پشت سی دی ان هست باید فقط از پورتای سی دی ان استفاده کنین و گرنه ارور میده

@LordDeveloper
Copy link

هیچی

متوجه

سلام بعد از اضافه کردن کاربرا با استفاده از وب سرویس xray با خطا مواجه میشه و دیگه کار نمیکنه راهی هست بشه متوجه شد که چرا بعد از اضافه کردن کاربران سیستم با خطا مواجه میشه ؟ یوزر به طور کامل و صحیح ایجاد میشه و ارسال میشه و در پنل با کلیه مشخصات وارد شده فعال میشه

1414

نمونه درخواست برای ایجاد کاربر:

{"up":0,"down":0,"total":96636764160,"remark":"Mirzaei","enable":true,"expiryTime":1674061858000,"listen":null,"port":5129,"protocol":"vmess","settings":"{"clients":[{"id":"df5001e7-080c-3603-bf56-0fbc26cf741f","email":"5129xxx@xxx.xxx","alterId":0,"limitIp":1,"totalGB":0,"expiryTime":""},{"id":"d2a818df-51df-3377-95f5-18d210ceaf6f","email":"5129xxxxx@xxxx.xxx","alterId":0,"limitIp":1,"totalGB":0,"expiryTime":""}],"disableInsecureEncryption":false}","streamSettings":"{"network":"ws","security":"none","wsSettings":{"acceptProxyProtocol":false,"path":"/","headers":[]}}","sniffing":"{"enabled":true,"destOverride":["http","tls"]}"}

اشتراک ایجاد شده

1313

جیسون اشتراک

{ "v": "2", "ps": "Mirzaei", "add": "xxxxxxxxxxx", "port": 4129, "id": "33c36149-ffe9-3474-948f-e932e067c703", "aid": 0, "net": "ws", "type": "none", "host": "", "path": "/", "tls": "none" }

حتی سرویس رو ریست کردم چند بار نصب کردم ولی هر باز بعد از ایجاد اشتراک xray با خطا مواجه میشه و کار نمیکنه هیچی !!!!

سلام وقتتون بخیر. مقدار headers نباید خالی باشه. اگه مقداری ندارید کلا حذفش کنین

@aladaghlou
Copy link

سلام. ممنون بابت به اشتراک گذاری این فایل جیسون. من همه متدهارو تست کردم درست کار میکنه فقط دریافت اطلاعات یک ردیف خطای 404 داد. اگر کسی حلش کرد بگه ممنون

@aladaghlou
Copy link

سلام، خدا قوت ظاهرا API بدون اعتبارسنجی به request ها پاسخ میده :| (غیر از http://localhost:1010/login که بررسی می‌کنه)

نه بدون کوکی خطا میده

@alirezax5
Copy link

آقا کار نمیکنه دارم دیوونه میشم لطفا یکی به منه نوب سگ بگه که مشکلم کجاست ممنون!

$post = [ 'username' => 'admin', 'password' => 'admin' ];

$ch = curl_init('https://domain.cf:2053/login'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'accept: application/json, text/plain, /', 'content-type: application/x-www-form-urlencoded; charset=UTF-8' )); $resp = curl_exec($ch); curl_close($ch); var_dump($resp);

ی چیز همینطوری نوشتم

https://github.com/alirezax5/xuiapi/blob/main/xUiapi.php

$a = new \alirezax5\XUiApi\xUiapi('ip:port, 'username', 'pass');
$a->login();
$a->getInbounds()

@theMeysam
Copy link

Postman collection attached

X-UI API.postman_collection3.zip

How to get proxy uri by API???

@mehdikhody
Copy link

Postman collection attached
X-UI API.postman_collection3.zip

How to get proxy uri by API???

For Vless:

vless://{client_id}@{server_ip}:{port}?type={transmission}&security=none&path={inbound_remark}

For Vmess::

{
  "v": "2",
  "ps": "{inbound_remark}",
  "add": "{server_ip}",
  "port": {port},
  "id": "{client_id}",
  "aid": 0,
  "net": "{transmission}",
  "type": "none",
  "host": "",
  "path": "/",
  "tls": "none"
}

then Encode the json from above to Base64 format with a vmess:// prefix.

vmess://ewogICJ2IjogIjIiLAogICJwcyI6ICJ7aW5ib3VuZF9yZW1hcmt9IiwKICAiYWRkIjogIntzZXJ2ZXJfaXB9IiwKICAicG9ydCI6IHtwb3J0fSwKICAiaWQiOiAie2NsaWVudF9pZH0iLAogICJhaWQiOiAwLAogICJuZXQiOiAie3RyYW5zbWlzc2lvbn0iLAogICJ0eXBlIjogIm5vbmUiLAogICJob3N0IjogIiIsCiAgInBhdGgiOiAiLyIsCiAgInRscyI6ICJub25lIgp9

@OghabTeam
Copy link

$a = new \alirezax5\XUiApi\xUiapi('ip:port, 'username', 'pass');
$a->login();
$a->getInbounds()

دمت گرم حاجی ولی خودت تستش کردی؟ چون برا من کار نکرد! ایدی تلتو میدی لطفا

@OghabTeam
Copy link

لاگ های مربوطه به api کجا ذخیره میشه؟ من یه مشکلی دارم جدیدا ریکوییست رو دریافت نمیکنه سرور میخوام ببینم چشه!!

@amira133
Copy link

hi, there
Is there any documentation how to work with panel?(persian or english or ...)

@userisamir
Copy link

@hossinasaadi
To Binaziri
Worked like a charm.

@alirayaneh
Copy link

missied "clientStats" on get inbound
for example
.../get/1
return null for "clientStats"

@younesatesh
Copy link

Postman collection attached

X-UI API.postman_collection3.zip

Hello, how do I use it? Look at the example below and see if it is correct or not.
https://mydomin/apps/v2.json?login/url=myserver:port&username=younes&password=1233

@mostafa9112
Copy link

Postman collection attached
X-UI API.postman_collection3.zip

Hello, how do I use it? Look at the example below and see if it is correct or not. https://mydomin/apps/v2.json?login/url=myserver:port&username=younes&password=1233

for login:
http://SERVERIP:PORT/PanelAddress/login?username=USERNAME&password=PASSWORD

use php CURL

@younesatesh
Copy link

http://SERVERIP:PORT/PanelAddress/login?username=USERNAME&password=PASSWORD

Are you sure brother? Because it didn't work for me

@YOUSSSOF
Copy link

should it necessarily done by a domain? I tried every possible port with ip address but it just gave 401. my mind is fucked up right now please help me.

@mostafa9112
Copy link

mostafa9112 commented Dec 23, 2022

@mostafa9112
Copy link

@hossinasaadi

plz update the api for more control and get mor info like get users

@mostafa9112
Copy link

سلام چجوری میتونم حجم استفاده شده client ها رو بگیرم ؟

سلام باید با متد getinbunds تمام کانفیگ ها رو بگیرید و در فایل جیسون دریافتی در بخش clientStats مصرف تمام کلاینت ها رو نوشته حتی کلاینت هایی که حذف شده اند

@mojtabaghasemi
Copy link

سلام وقت بخیر ، وقتی با وب سرویس یوزر ساخته میشه پنل با خطا مواجه میشه و دیگه کار نمیکنه .
Screenshot from 2022-12-29 12-44-31

Repository owner locked as off-topic and limited conversation to collaborators Dec 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.