import asyncio
import aiohttp
import json
import os
from dotenv import load_dotenv

load_dotenv()

async def test_vtiger():
    base_url = os.getenv('VTIGER_URL')
    username = os.getenv('VTIGER_USERNAME')
    api_key = os.getenv('VTIGER_API_KEY')
    
    auth = aiohttp.BasicAuth(username, api_key)
    
    # Test query with singular "Subscription"
    vtiger_id = '3x760'
    query = f"SELECT * FROM Subscription WHERE account_id='{vtiger_id}';"
    print(f"🔍 Testing query: {query}")
    
    async with aiohttp.ClientSession() as session:
        async with session.get(
            f"{base_url}/restapi/v1/vtiger/default/query",
            params={"query": query},
            auth=auth
        ) as response:
            text = await response.text()
            print(f"Status: {response.status}")
            print(f"Response: {text[:500]}")
            if response.status == 200:
                data = json.loads(text)
                print(json.dumps(data, indent=2))

asyncio.run(test_vtiger())
