diff --git a/.last-branch b/.last-branch index 712b150..fe28a48 100644 --- a/.last-branch +++ b/.last-branch @@ -1 +1 @@ -v20260115-10-autotask-customers-settings-helper-fix +v20260115-11-autotask-companyname-unwrap diff --git a/containers/backupchecks/src/backend/app/main/routes_customers.py b/containers/backupchecks/src/backend/app/main/routes_customers.py index aaf202f..f57ca44 100644 --- a/containers/backupchecks/src/backend/app/main/routes_customers.py +++ b/containers/backupchecks/src/backend/app/main/routes_customers.py @@ -113,7 +113,25 @@ def api_autotask_companies_search(): def _normalize_company_name(company: dict) -> str: - return str(company.get("companyName") or company.get("CompanyName") or company.get("name") or "").strip() + # Autotask REST payload shapes vary between tenants/endpoints. + # - Some single-entity GETs return {"item": {...}} + # - Some may return {"items": [{...}]} + if isinstance(company, dict): + item = company.get("item") + if isinstance(item, dict): + company = item + else: + items = company.get("items") + if isinstance(items, list) and items and isinstance(items[0], dict): + company = items[0] + + return str( + (company or {}).get("companyName") + or (company or {}).get("CompanyName") + or (company or {}).get("name") + or (company or {}).get("Name") + or "" + ).strip() @main_bp.get("/api/customers//autotask-mapping") diff --git a/docs/changelog.md b/docs/changelog.md index 9e4b2d9..ec0cd13 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -88,7 +88,11 @@ Changes: - Added a local SystemSettings get-or-create helper in customers routes to prevent runtime NameError in mixed/partial deployments. - Added explicit imports for SystemSettings, db, and datetime to keep the Customers page stable across versions. +## v20260115-11-autotask-companyname-unwrap +- Fixed Autotask company name being shown as "Unknown" by correctly unwrapping nested Autotask API responses. +- Improved company lookup handling to support different response shapes (single item and collection wrappers). +- Ensured the cached Autotask company name is stored and displayed consistently after mapping and refresh. ***