Files
Brancheneinstufung2/connector-superoffice/tools/create_company.py
Floke 50764c4490 [31188f42] Fix: Default-Umgebung auf 'online3' gesetzt & Test-Suite hinzugefügt.
- config.py: Standard-Environment auf 'online3' geändert, um Auth-Fehler ohne .env zu beheben.
- tools/create_company.py: Skript zum Anlegen von Test-Accounts in Prod.
- tools/get_enriched_company_data.py: Diagnose-Tool für API-Antworten.
- tools/verify_enrichment.py: Verifikations-Skript (zeigt aktuelles UDF-Problem).
2026-03-04 16:30:57 +00:00

57 lines
2.1 KiB
Python

import sys
import os
from dotenv import load_dotenv
# Explicitly load .env from the parent directory
dotenv_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '.env'))
print(f"Loading .env from: {dotenv_path}")
load_dotenv(dotenv_path=dotenv_path, override=True)
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from superoffice_client import SuperOfficeClient
def create_test_company():
"""
Creates a new company in SuperOffice for E2E testing.
"""
company_name = "Bremer Abenteuerland"
# Provide a real-world, scrapable website to test enrichment
website = "https://www.belantis.de/"
print(f"🚀 Attempting to create company: '{company_name}'")
try:
client = SuperOfficeClient()
if not client.access_token:
print("❌ Authentication failed. Check your .env file.")
return
# Check if company already exists
existing = client.search(f"Contact?$select=contactId,name&$filter=name eq '{company_name}'")
if existing:
contact_id = existing[0]['ContactId']
print(f"⚠️ Company '{company_name}' already exists with ContactId: {contact_id}.")
print("Skipping creation.")
return contact_id
payload = {
"Name": company_name,
"Urls": [
{
"Value": website,
"Description": "Main Website"
}
],
"Country": {
"CountryId": 68 # Germany
}
}
new_company = client._post("Contact", payload)
if new_company and "ContactId" in new_company:
contact_id = new_company["ContactId"]
print(f"✅ SUCCESS! Created company '{company_name}' with ContactId: {contact_id}")
return contact_id
else:
print(f"❌ Failed to create company. Response: {new_company}")
return None
except Exception as e:
print(f"An error occurred: {e}")
return None
if __name__ == "__main__":
create_test_company()