Files
Brancheneinstufung2/connector-superoffice/discover_fields.py

83 lines
2.9 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) ---")
# Contact UDFs
try:
print("Fetching a sample Contact to inspect UDFs...")
contacts = client.search("Contact?$top=1")
if contacts:
# Inspect keys of first result
first_contact = contacts[0]
# Try to find ID
c_id = first_contact.get('ContactId') or first_contact.get('PrimaryKey')
if c_id:
c = client.get_contact(c_id)
udfs = c.get("UserDefinedFields", {})
print(f"Found {len(udfs)} UDFs on Contact {c_id}:")
for k, v in udfs.items():
print(f" - Key (ProgId): {k} | Value: {v}")
else:
print(f"⚠️ Could not find ID in search result: {first_contact.keys()}")
else:
print("⚠️ No contacts found. Cannot inspect Contact UDFs.")
print("\nFetching a sample Person to inspect UDFs...")
persons = client.search("Person?$top=1")
if persons:
first_person = persons[0]
p_id = first_person.get('PersonId') or first_person.get('PrimaryKey')
if p_id:
p = client.get_person(p_id)
udfs = p.get("UserDefinedFields", {})
print(f"Found {len(udfs)} UDFs on Person {p_id}:")
for k, v in udfs.items():
print(f" - Key (ProgId): {k} | Value: {v}")
else:
print(f"⚠️ Could not find ID in search result: {first_person.keys()}")
else:
print("⚠️ No persons found. Cannot inspect Person UDFs.")
except Exception as e:
print(f"❌ Error inspecting UDFs: {e}")
# 2. Discover Lists (MDO Providers)
print("\n--- 2. MDO Lists (Positions, Business/Industry) ---")
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()