[2ff88f42] 1. Analyse der Änderungen:
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.
This commit is contained in:
@@ -89,3 +89,63 @@ class SuperOfficeClient:
|
||||
except Exception as e:
|
||||
logger.error(f"Error searching for contact: {e}")
|
||||
return None
|
||||
|
||||
def create_contact(self, name, url=None, org_nr=None):
|
||||
"""Creates a new contact (company) in SuperOffice with basic details."""
|
||||
url = self._get_url("v1/Contact")
|
||||
payload = {
|
||||
"Name": name,
|
||||
"OrgNr": org_nr,
|
||||
"UrlAddress": url,
|
||||
"ActivePublications": [], # Required field, can be empty
|
||||
"Emails": [], # Required field, can be empty
|
||||
"Phones": [] # Required field, can be empty
|
||||
}
|
||||
|
||||
# Remove None values
|
||||
payload = {k: v for k, v in payload.items() if v is not None}
|
||||
|
||||
try:
|
||||
logger.info(f"Attempting to create contact: {name}")
|
||||
resp = self.session.post(url, headers=self._get_headers(), json=payload)
|
||||
resp.raise_for_status()
|
||||
created_contact = resp.json()
|
||||
logger.info(f"Successfully created contact: {created_contact.get('Name')} (ID: {created_contact.get('ContactId')})")
|
||||
return created_contact
|
||||
except Exception as e:
|
||||
if hasattr(e, 'response') and e.response is not None:
|
||||
logger.error(f"Response: {e.response.text}")
|
||||
return None
|
||||
|
||||
def create_person(self, first_name, last_name, contact_id, email=None):
|
||||
"""Creates a new person linked to a contact (company)."""
|
||||
url = self._get_url("v1/Person")
|
||||
|
||||
payload = {
|
||||
"Firstname": first_name,
|
||||
"Lastname": last_name,
|
||||
"Contact": {
|
||||
"ContactId": contact_id
|
||||
},
|
||||
"Emails": []
|
||||
}
|
||||
|
||||
if email:
|
||||
payload["Emails"].append({
|
||||
"Value": email,
|
||||
"Rank": 1,
|
||||
"Description": "Work" # Optional description
|
||||
})
|
||||
|
||||
try:
|
||||
logger.info(f"Attempting to create person: {first_name} {last_name} for Contact ID {contact_id}")
|
||||
resp = self.session.post(url, headers=self._get_headers(), json=payload)
|
||||
resp.raise_for_status()
|
||||
created_person = resp.json()
|
||||
logger.info(f"Successfully created person: {created_person.get('Firstname')} {created_person.get('Lastname')} (ID: {created_person.get('PersonId')})")
|
||||
return created_person
|
||||
except Exception as e:
|
||||
logger.error(f"Error creating person: {e}")
|
||||
if hasattr(e, 'response') and e.response is not None:
|
||||
logger.error(f"Response: {e.response.text}")
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user