iwatkot / py3xui

Sync and Async Object-oriented Python SDK for the 3x-ui API.
MIT License
8 stars 1 forks source link

expiry_time attribute doesnt work #8

Closed SpiritFoxo closed 2 weeks ago

SpiritFoxo commented 2 weeks ago

when i try to add new client with limited duration it doesnt work. It just creates new client with expiry_time=0

iwatkot commented 2 weeks ago

@SpiritFoxo, hello!

Thank you for reaching out. I would like to ask you if the following approach is working in your case:

  1. Create a new client.
  2. Update a client with the needed attribute.

Code reference for traffic limit:

async def some_other_function():
    user_uuid = str(uuid.uuid4())
    new_client = Client(id=user_uuid, email=str(telegram_id), enable=True)

    await api.client.add(inbound.id, [new_client])

    await set_traffic_limit(telegram_id, user_uuid)

async def set_traffic_limit(telegram_id: int, user_uuid: str) -> None:
    client = await api.client.get_by_email(str(telegram_id))
    client.id = user_uuid
    client.total_gb = gigabytes_to_bytes(Settings().traffic_limit)
    await api.client.update(user_uuid, client)

When working with 3x-ui API I found out that some of the fields may be ignored by the API on user create, even if they were passed (or maybe I'm doing something wrong). So I used this workaround to set the traffic limit, maybe it will help you too.

Sincerely

iwatkot commented 2 weeks ago

As an additional check, I also would like to ask for help to test if the simple POST request without SDK will work for this case, so we can check if the issue is in the SDK or on the API side.

SpiritFoxo commented 2 weeks ago

Oh, yeah. Thats works. Thanks for fast response!