Skip to content

👤 API: Hồ sơ khách hàng

Tóm tắt

Các API phục vụ panel Customer Profile trên giao diện agent. Dữ liệu chi tiết được lấy từ Bitrix theo nhu cầu — không nằm trong callback đăng nhập.

GET /api/method/haravan_bitrix_customer_profile

Endpoint production của Server Script Profile - Bitrix Customer API. Endpoint kiểm tra quyền đọc HD Ticket, lấy HD CustomerContact liên quan, tạo danh sách ứng viên Haravan Company ID từ ticket/customer, rồi gọi Bitrix server-side bằng crm.company.list filter UF_CRM_COMPANY_ID nếu cấu hình đang bật. Bitrix internal ID chỉ dùng để build link details.

Tham số

Tham sốKiểuBắt buộcMô tả
ticketstringHD Ticket
refresh0/1Ép lấy lại dữ liệu từ Bitrix

Phản hồi

json
{
  "success": true,
  "data": {
    "customer": {},
    "contact": {},
    "haravan": [],
    "bitrix": {
      "enabled": true,
      "configured": true,
      "status": "matched",
      "cached": false,
      "lookup_candidates": ["200000317825", "1900000017"],
      "lookup_value": "1900000017",
      "company": {},
      "contact": {},
      "responsible": {
        "id": "338",
        "active": true,
        "email": "agent@example.com",
        "name": "Nguyen An",
        "user_type": "employee",
        "status": "active"
      }
    }
  },
  "message": "Customer profile loaded."
}
TrườngMô tả
data.customerThông tin HD Customer
data.contactThông tin Contact
data.bitrix.enabledTích hợp Bitrix có đang bật không
data.bitrix.configuredWebhook Bitrix đã được cấu hình server-side chưa
data.bitrix.statusTrạng thái: disabled, missing_config, missing_orgid, matched, not_found, error, cached
data.bitrix.cachedResponse đang dùng cache trong TTL
data.bitrix.lookup_candidatesCác Haravan Company ID đã thử theo thứ tự ưu tiên
data.bitrix.lookup_valueCandidate cuối cùng dùng cho match hoặc candidate cuối cùng đã thử
data.bitrix.companyDữ liệu công ty Bitrix đã normalize, gồm bitrix_id, company_id, company_name, HSI, Shopplan, url
data.bitrix.contactDữ liệu contact từ Bitrix
data.bitrix.responsibleUser phụ trách resolve từ ASSIGNED_BY_ID qua user.get; nếu active = true, EMAIL được ghi vào HD Ticket.custom_responsible

Bảo mật

Bitrix token/webhook URL không bao giờ được trả về browser. Production đọc bitrix_webhook_url cho customer/company và bitrix_responsible_webhook_url cho responsible từ Helpdesk Integrations Settings bằng get_password(); mọi gọi Bitrix đều thực hiện server-side.

Legacy app endpoint

GET /api/method/login_with_haravan.customer_profile.get_ticket_customer_profile vẫn tồn tại trong custom app cho panel phụ, nhưng HD Form Script production hiện gọi haravan_bitrix_customer_profile.

POST /api/method/login_with_haravan.customer_profile.refresh_customer_profile

Làm mới hồ sơ theo HD Customer và optional Contact. Gọi lại Bitrix để cập nhật dữ liệu mới nhất.

Tham số

Tham sốKiểuBắt buộcMô tả
hd_customerstringTên HD Customer
contactstringTên Contact (nếu muốn refresh cụ thể)

POST /api/method/haravan_bitrix_metajson_company_enrichment

Endpoint production dạng Server Script, dùng cho workflow metajson muốn làm giàu HD Customer theo Haravan orgid mà không cần thêm runtime logic vào custom app.

Script được deploy từ:

text
scripts/deploy_bitrix_metajson_enrichment.py

Tham số

Tham sốKiểuBắt buộcMô tả
orgidstring/intHaravan org id dùng để lookup Bitrix company
force0/1Bỏ qua TTL và ép kiểm tra Bitrix
hd_customerstringTên HD Customer nếu caller đã resolve sẵn
ticket / ticket_name / hd_ticketstringHD Ticket cần link vào HD Customer sau khi enrichment

Hành vi guard

  • Không có orgid thì trả missing_orgid, không ghi Error Log.
  • Trong TTL bitrix_refresh_ttl_minutes thì trả cached, không gọi Bitrix.
  • Nếu Bitrix trả nhiều company, lấy record đầu tiên từ kết quả đã order theo DATE_MODIFY DESC.
  • Nếu DATE_MODIFY không đổi, chỉ touch custom_bitrix_last_checked_at; không save lại dữ liệu business.
  • Nếu dữ liệu mới hơn/khác, cập nhật HD Customer và upsert snapshot vào HD Customer Data.
  • Nếu truyền ticket, script set HD Ticket.customer về HD Customer đã resolve/tạo; nếu customer đã tồn tại thì chỉ link ticket.