import sys import os import json # Absolute path to the connector-superoffice directory current_dir = os.path.dirname(os.path.abspath(__file__)) connector_dir = os.path.abspath(os.path.join(current_dir, '..')) # CRITICAL: Insert at 0 to shadow /app/config.py sys.path.insert(0, connector_dir) from superoffice_client import SuperOfficeClient def discover_verticals(): print("šŸ”Ž Starting Final Vertical Discovery (Production)...") client = SuperOfficeClient() if not client.access_token: print("āŒ Auth failed.") return # 1. Fetch Contact UDF Layout to find the List ID behind SuperOffice:83 print("šŸ“” Fetching Contact UDF Layout (Metadata)...") layout = client._get("Contact/UdefLayout/Published") list_id = None if layout and 'Fields' in layout: for field in layout['Fields']: if field.get('ProgId') == 'SuperOffice:83': print(f"āœ… Found SuperOffice:83: {field.get('Label')}") list_id = field.get('ListId') print(f"āœ… List ID: {list_id}") break if not list_id: print("āŒ Could not find Metadata for SuperOffice:83.") return # 2. Fetch the List Items for this List print(f"šŸ“” Fetching List Items for List ID {list_id}...") # List endpoint is typically List/ListId/Items # Let's try to get all rows for this list items = client._get(f"List/{list_id}/Items") if items: print(f"āœ… SUCCESS! Found {len(items)} items in the Vertical list.") mapping = {} for item in items: name = item.get('Value') or item.get('Name') item_id = item.get('Id') mapping[name] = item_id print(f" - {name}: {item_id}") print("\nšŸš€ FINAL MAPPING JSON (Copy to .env VERTICAL_MAP_JSON):") print(json.dumps(mapping)) else: print(f"āŒ Could not fetch items for List {list_id}. Trying MDO List...") # Fallback to MDO List mdo_items = client._get(f"MDOList/udlist{list_id}") if mdo_items: print("āœ… Success via MDO List.") # ... process mdo items if needed ... else: print("āŒ MDO List fallback failed too.") if __name__ == "__main__": discover_verticals()