#!/usr/bin/env python3
"""Дебаг запроса к ServiceDesk Plus API v3."""

import asyncio
import httpx
import json
import urllib3

BASE_URL = "https://192.168.1.237:8080"
API_TOKEN = "062CE056-C1F5-490C-A6DF-FD2C653A71DD"

async def debug():
    url = f"{BASE_URL}/api/v3/requests"
    headers = {
        "authtoken": API_TOKEN,
        "Accept": "application/vnd.manageengine.sdp.v3+json"
    }
    
    # Разные варианты формата
    variants = [
        # Вариант 1: input_data как JSON
        {
            "input_data": json.dumps({
                "list_info": {
                    "row_count": 5,
                    "start_index": 1
                }
            })
        },
        # Вариант 2: без input_data, просто параметры
        None,
        # Вариант 3: input_data без json.dumps
        {
            "input_data": {
                "list_info": {
                    "row_count": 5,
                    "start_index": 1
                }
            }
        }
    ]
    
    for i, params in enumerate(variants):
        print(f"\n=== Вариант {i+1} ===")
        print(f"Params: {params}")
        
        async with httpx.AsyncClient(verify=False, timeout=15.0) as client:
            try:
                resp = await client.get(url, headers=headers, params=params)
                print(f"HTTP {resp.status_code}")
                print(f"Response: {resp.text[:500]}")
            except Exception as e:
                print(f"Error: {e}")

if __name__ == "__main__":
    urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
    asyncio.run(debug())
