operations-granite/HuggingFace-Granite-AI-Practice-Agent-Dev
0
1"""2Test script to call Zoho API and see ALL fields for accounts and contacts3"""4import asyncio5import json6from backend.services.zoho_crm_service import get_zoho_service7 8async def test_all_fields():9 """Fetch sample records and show all available fields"""10 zoho = get_zoho_service()11 12 # Test 1: Get account by ID (should return all fields)13 print("=" * 80)14 print("TEST 1: ACCOUNT FIELDS")15 print("=" * 80)16 try:17 # First get list of accounts18 accounts = await zoho.get_accounts(limit=1)19 if accounts:20 account_id = accounts[0]['id']21 print(f"Found account ID: {account_id}")22 23 # Now get full account record24 account = await zoho.get_account(account_id)25 26 if account:27 print(f"\nAccount Name: {account.get('Account_Name', 'N/A')}")28 print(f"\nTotal Fields: {len(account)}")29 print("\nFIELDS:")30 for key in sorted(account.keys()):31 value = account[key]32 if isinstance(value, str) and len(value) > 80:33 value = value[:80] + "..."34 elif isinstance(value, dict):35 value = f"<dict with {len(value)} keys>"36 print(f" {key:35s} : {value}")37 38 with open('zoho_account_all_fields.json', 'w') as f:39 json.dump(account, f, indent=2, default=str)40 print(f"\n✓ Saved to: zoho_account_all_fields.json")41 else:42 print("No accounts found")43 except Exception as e:44 print(f"Error: {e}")45 import traceback46 traceback.print_exc()47 48 # Test 2: Get contact by ID49 print("\n" + "=" * 80)50 print("TEST 2: CONTACT FIELDS")51 print("=" * 80)52 try:53 contacts = await zoho.get_contacts(limit=1)54 if contacts:55 contact_id = contacts[0]['id']56 print(f"Found contact ID: {contact_id}")57 58 contact = await zoho.get_contact(contact_id)59 60 if contact:61 print(f"\nContact Name: {contact.get('Full_Name', 'N/A')}")62 print(f"\nTotal Fields: {len(contact)}")63 print("\nFIELDS:")64 for key in sorted(contact.keys()):65 value = contact[key]66 if isinstance(value, str) and len(value) > 80:67 value = value[:80] + "..."68 elif isinstance(value, dict):69 value = f"<dict with {len(value)} keys>"70 print(f" {key:35s} : {value}")71 72 with open('zoho_contact_all_fields.json', 'w') as f:73 json.dump(contact, f, indent=2, default=str)74 print(f"\n✓ Saved to: zoho_contact_all_fields.json")75 else:76 print("No contacts found")77 except Exception as e:78 print(f"Error: {e}")79 import traceback80 traceback.print_exc()81 82if __name__ == "__main__":83 asyncio.run(test_all_fields())84 