diff --git a/connector-superoffice/config.py b/connector-superoffice/config.py index e9afbea7..ca78ea04 100644 --- a/connector-superoffice/config.py +++ b/connector-superoffice/config.py @@ -9,7 +9,7 @@ class Settings: # --- SuperOffice API Credentials --- # Fallback for empty string in env var env_val = os.getenv("SO_ENVIRONMENT") - self.SO_ENVIRONMENT = env_val if env_val else "sod" + self.SO_ENVIRONMENT = env_val if env_val else "online3" self.SO_CLIENT_ID = os.getenv("SO_CLIENT_ID", "") self.SO_CLIENT_SECRET = os.getenv("SO_CLIENT_SECRET", "") diff --git a/connector-superoffice/tools/create_company.py b/connector-superoffice/tools/create_company.py new file mode 100644 index 00000000..3e058c33 --- /dev/null +++ b/connector-superoffice/tools/create_company.py @@ -0,0 +1,56 @@ +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() diff --git a/connector-superoffice/tools/debug_config_types.py b/connector-superoffice/tools/debug_config_types.py new file mode 100644 index 00000000..3ba1cab0 --- /dev/null +++ b/connector-superoffice/tools/debug_config_types.py @@ -0,0 +1,40 @@ + +import sys +import os +from dotenv import load_dotenv + +# Explicitly load .env from the project root +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 config import settings + +print("\n--- DEBUGGING CONFIG TYPES ---") +try: + print(f"UDF_VERTICAL: {settings.UDF_VERTICAL} (Type: {type(settings.UDF_VERTICAL)})") + print(f"UDF_SUMMARY: {settings.UDF_SUMMARY} (Type: {type(settings.UDF_SUMMARY)})") + print(f"UDF_OPENER: {settings.UDF_OPENER} (Type: {type(settings.UDF_OPENER)})") + print(f"UDF_OPENER_SECONDARY: {settings.UDF_OPENER_SECONDARY} (Type: {type(settings.UDF_OPENER_SECONDARY)})") + print(f"UDF_LAST_UPDATE: {settings.UDF_LAST_UPDATE} (Type: {type(settings.UDF_LAST_UPDATE)})") + print(f"UDF_LAST_OUTREACH: {settings.UDF_LAST_OUTREACH} (Type: {type(settings.UDF_LAST_OUTREACH)})") + + # Test dictionary creation to force the error if a key is a dict + print("\nAttempting to create dictionary with these keys...") + test_dict = { + settings.UDF_VERTICAL: "Vertical", + settings.UDF_SUMMARY: "Summary", + settings.UDF_OPENER: "Opener", + settings.UDF_OPENER_SECONDARY: "Opener 2", + settings.UDF_LAST_UPDATE: "Last Update", + settings.UDF_LAST_OUTREACH: "Last Outreach" + } + print("āœ… Dictionary creation SUCCESSFUL.") + +except TypeError as e: + print(f"\nāŒ TypeError CAUGHT: {e}") + print("One of the settings above is likely a dictionary or unhashable type!") + +except Exception as e: + print(f"\nāŒ Unknown Error: {e}") diff --git a/connector-superoffice/tools/get_enriched_company_data.py b/connector-superoffice/tools/get_enriched_company_data.py new file mode 100644 index 00000000..4e0e5be4 --- /dev/null +++ b/connector-superoffice/tools/get_enriched_company_data.py @@ -0,0 +1,84 @@ + +import sys +import os +import json +import traceback +from dotenv import load_dotenv + +# Explicitly load .env from the project root +dotenv_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '.env')) +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 +from config import settings + +def get_enriched_data(contact_id: int): + print(f"šŸš€ [DEBUG] Starting fetch for ContactId: {contact_id}") + try: + client = SuperOfficeClient() + if not client.access_token: + print("āŒ Authentication failed.") + return + + print("āœ… [DEBUG] Client authenticated.") + + try: + contact_data = client.get_contact( + contact_id, + select=[ + "Name", "UrlAddress", "OrgNr", "UserDefinedFields" + ] + ) + print(f"āœ… [DEBUG] API Call successful. Data type: {type(contact_data)}") + except Exception as e: + print(f"āŒ [DEBUG] API Call failed: {e}") + traceback.print_exc() + return + + if not contact_data: + print("āŒ [DEBUG] No data returned.") + return + + print(f"āœ… [DEBUG] Name: {contact_data.get('Name')}") + + try: + udfs = contact_data.get("UserDefinedFields", {}) + print(f"āœ… [DEBUG] UDFs extracted. Type: {type(udfs)}") + except Exception as e: + print(f"āŒ [DEBUG] Failed to extract UDFs: {e}") + traceback.print_exc() + return + + if isinstance(udfs, dict): + print(f"āœ… [DEBUG] UDFs is a dict with {len(udfs)} keys.") + try: + # Iterate keys safely + print("--- UDF KEYS SAMPLE ---") + for k in list(udfs.keys())[:5]: + print(f"Key: {k} (Type: {type(k)})") + except Exception as e: + print(f"āŒ [DEBUG] Failed to iterate keys: {e}") + traceback.print_exc() + + # Try to access specific key + target_key = settings.UDF_VERTICAL + print(f"āœ… [DEBUG] Attempting access with key: '{target_key}' (Type: {type(target_key)})") + + try: + if target_key in udfs: + val = udfs[target_key] + print(f"āœ… [DEBUG] Value found: {val}") + else: + print(f"ā„¹ļø [DEBUG] Key not found in UDFs.") + except Exception as e: + print(f"āŒ [DEBUG] Failed to access dictionary with key: {e}") + traceback.print_exc() + + except Exception as e: + print(f"āŒ [DEBUG] Global Error: {e}") + traceback.print_exc() + +if __name__ == "__main__": + target_contact_id = 171185 + get_enriched_data(target_contact_id) diff --git a/connector-superoffice/tools/verify_enrichment.py b/connector-superoffice/tools/verify_enrichment.py new file mode 100644 index 00000000..3f323ae2 --- /dev/null +++ b/connector-superoffice/tools/verify_enrichment.py @@ -0,0 +1,69 @@ +import sys +import os +import json +from dotenv import load_dotenv + +# Explicitly load .env from the project root +dotenv_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '.env')) +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 +from config import settings + +def verify_enrichment(contact_id: int): + print(f"šŸš€ Verifying enrichment for ContactId: {contact_id}") + try: + client = SuperOfficeClient() + if not client.access_token: + print("āŒ Authentication failed.") + return + + contact_data = client.get_contact( + contact_id, + select=[ + "Name", "UrlAddress", "Urls", "OrgNr", "Address", "UserDefinedFields" + ] + ) + + if not contact_data: + print(f"āŒ Contact {contact_id} not found.") + return + + print("\n--- šŸ¢ Company Profile (SuperOffice) ---") + print(f"Name: {contact_data.get('Name')}") + print(f"Website: {contact_data.get('UrlAddress')}") + print(f"VAT/OrgNr: {contact_data.get('OrgNr')}") + + udfs = contact_data.get("UserDefinedFields", {{}}) + + print("\n--- šŸ¤– AI Enrichment Data ---") + + # Helper to safely get UDF value + def get_udf(key, label): + safe_key = str(key) # FORCE STRING CONVERSION + if not isinstance(key, str): + print(f"āš ļø WARNING: Key for '{label}' is not a string! Type: {type(key)} Value: {key}") + + if safe_key in udfs: + val = udfs[safe_key] + print(f"{label:<25}: {val}") + else: + print(f"{label:<25}: [Not Set] (Key: {safe_key})") + + get_udf(settings.UDF_VERTICAL, "Vertical (Branche)") + get_udf(settings.UDF_SUMMARY, "AI Summary") + get_udf(settings.UDF_OPENER, "AI Opener Primary") + get_udf(settings.UDF_OPENER_SECONDARY, "AI Opener Secondary") + get_udf(settings.UDF_LAST_UPDATE, "AI Last Update") + get_udf(settings.UDF_LAST_OUTREACH, "Date Last Outreach") + + print("\n-----------------------------------") + print("āœ… Verification Complete.") + + except Exception as e: + print(f"āŒ Error during verification: {e}") + +if __name__ == "__main__": + target_contact_id = 171185 + verify_enrichment(target_contact_id) \ No newline at end of file