63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
import json
|
|
from superoffice_client import SuperOfficeClient
|
|
import logging
|
|
|
|
# Setup Logging
|
|
logging.basicConfig(level=logging.INFO)
|
|
logger = logging.getLogger("discovery")
|
|
|
|
def discover():
|
|
print("🔍 Starting SuperOffice Discovery Tool...")
|
|
|
|
client = SuperOfficeClient()
|
|
if not client.access_token:
|
|
print("❌ Auth failed. Check .env")
|
|
return
|
|
|
|
# 1. Discover UDFs (User Defined Fields)
|
|
print("\n--- 1. User Defined Fields (UDFs) Definitions ---")
|
|
try:
|
|
# Fetch Metadata about UDFs to get Labels
|
|
udf_info = client._get("UserDefinedFieldInfo")
|
|
if udf_info:
|
|
print(f"Found {len(udf_info)} UDF definitions.")
|
|
|
|
# Filter for Contact and Person UDFs
|
|
contact_udfs = [u for u in udf_info if u['UDTargetEntityName'] == 'Contact']
|
|
person_udfs = [u for u in udf_info if u['UDTargetEntityName'] == 'Person']
|
|
|
|
print(f"\n--- CONTACT UDFs ({len(contact_udfs)}) ---")
|
|
for u in contact_udfs:
|
|
print(f" - Label: '{u['FieldLabel']}' | ProgId: '{u['ProgId']}' | Type: {u['UDFieldType']}")
|
|
|
|
print(f"\n--- PERSON UDFs ({len(person_udfs)}) ---")
|
|
for u in person_udfs:
|
|
print(f" - Label: '{u['FieldLabel']}' | ProgId: '{u['ProgId']}' | Type: {u['UDFieldType']}")
|
|
|
|
else:
|
|
print("❌ Could not fetch UserDefinedFieldInfo.")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Error fetching UDF Info: {e}")
|
|
|
|
print("\n--- 2. Sample Data Inspection ---")
|
|
|
|
lists_to_check = ["position", "business"]
|
|
|
|
for list_name in lists_to_check:
|
|
print(f"\nChecking List: '{list_name}'...")
|
|
try:
|
|
# Endpoint: GET /List/{list_name}/Items
|
|
items = client._get(f"List/{list_name}/Items")
|
|
if items:
|
|
print(f"Found {len(items)} items in '{list_name}':")
|
|
for item in items:
|
|
print(f" - ID: {item['Id']} | Name: '{item['Name']}'")
|
|
else:
|
|
print(f" (List '{list_name}' is empty or not accessible)")
|
|
except Exception as e:
|
|
print(f" ❌ Failed to fetch list '{list_name}': {e}")
|
|
|
|
if __name__ == "__main__":
|
|
discover()
|