1. Analyse der Änderungen:
* superoffice_client.py: Implementierung der Methoden create_contact (Standardfelder) und create_person (inkl. Firmenverknüpfung).
* auth_handler.py: Härtung der Authentifizierung durch Priorisierung von SO_CLIENT_ID und Unterstützung für load_dotenv(override=True).
* main.py: Erweiterung des Test-Workflows für den vollständigen Lese- und Schreib-Durchstich (Erstellung von Demo-Firmen und Personen).
* README.md: Aktualisierung des Status Quo und der verfügbaren Client-Methoden.
92 lines
3.3 KiB
Python
92 lines
3.3 KiB
Python
import os
|
|
import logging
|
|
from dotenv import load_dotenv
|
|
from auth_handler import AuthHandler
|
|
from superoffice_client import SuperOfficeClient
|
|
|
|
# Setup logging
|
|
logging.basicConfig(
|
|
level=logging.INFO,
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
def main():
|
|
# Load .env from the root directory
|
|
# If running from /app, .env is in the same directory.
|
|
# If running from /app/connector-superoffice, it's in ../.env
|
|
if os.path.exists(".env"):
|
|
load_dotenv(".env", override=True)
|
|
elif os.path.exists("../.env"):
|
|
load_dotenv("../.env", override=True)
|
|
|
|
logger.info("Starting SuperOffice Connector S2S POC...")
|
|
|
|
try:
|
|
# Initialize Auth
|
|
auth = AuthHandler()
|
|
|
|
# Initialize Client
|
|
client = SuperOfficeClient(auth)
|
|
|
|
# 1. Test Connection
|
|
logger.info("Step 1: Testing connection...")
|
|
user_info = client.test_connection()
|
|
if user_info:
|
|
logger.info(f"Connected successfully as: {user_info.get('Name')}")
|
|
else:
|
|
logger.error("Connection test failed.")
|
|
return
|
|
|
|
# 2. Search for our demo company
|
|
demo_company_name = "Gemini Test Company [2ff88f42]"
|
|
logger.info(f"Step 2: Searching for company '{demo_company_name}'...")
|
|
contact = client.find_contact_by_criteria(name=demo_company_name)
|
|
|
|
target_contact_id = None
|
|
|
|
if contact:
|
|
target_contact_id = contact.get('ContactId')
|
|
logger.info(f"Found existing demo company: {contact.get('Name')} (ID: {target_contact_id})")
|
|
else:
|
|
logger.info(f"Demo company not found. Creating new one...")
|
|
demo_company_url = "https://www.gemini-test-company.com"
|
|
demo_company_orgnr = "DE123456789"
|
|
|
|
new_contact = client.create_contact(
|
|
name=demo_company_name,
|
|
url=demo_company_url,
|
|
org_nr=demo_company_orgnr
|
|
)
|
|
if new_contact:
|
|
target_contact_id = new_contact.get('ContactId')
|
|
logger.info(f"Created new demo company with ID: {target_contact_id}")
|
|
|
|
# 3. Create a Person linked to this company
|
|
if target_contact_id:
|
|
logger.info(f"Step 3: Creating Person for Contact ID {target_contact_id}...")
|
|
|
|
# Create Max Mustermann
|
|
person = client.create_person(
|
|
first_name="Max",
|
|
last_name="Mustermann",
|
|
contact_id=target_contact_id,
|
|
email="max.mustermann@gemini-test.com"
|
|
)
|
|
|
|
if person:
|
|
logger.info("SUCCESS: Person created!")
|
|
logger.info(f"Name: {person.get('Firstname')} {person.get('Lastname')}")
|
|
logger.info(f"Person ID: {person.get('PersonId')}")
|
|
logger.info(f"Linked to Contact ID: {person.get('Contact').get('ContactId')}")
|
|
else:
|
|
logger.error("Failed to create person.")
|
|
else:
|
|
logger.error("Skipping person creation because company could not be found or created.")
|
|
|
|
except Exception as e:
|
|
logger.error(f"An error occurred: {e}", exc_info=True)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|