CRMKhách hàng

Nhập khách hàng hàng loạt

Tạo nhiều khách hàng trong một request (tối đa 10.000 dòng).

Endpoint

POST /v1/customers/import

Quyền: customer.manage

Body Parameters

TênKiểuBắt buộcMô tả
company_idintCóID công ty
itemsarrayCóDanh sách khách hàng cần tạo (tối đa 10.000 phần tử)

Mỗi phần tử trong items hỗ trợ các trường sau (ý nghĩa giống Thêm mới khách hàng):

TênKiểuBắt buộcMô tả
full_namestringCóTên đầy đủ
codestringMã khách hàng (chỉ chấp nhận a-z, A-Z, 0-9, _, -, .)
phonestringSố điện thoại (≥ 8 ký tự số)
emailstringEmail
birthdaystringNgày sinh (DD/MM/YYYY)
genderintGiới tính
addressstringĐịa chỉ
region_idintID Tỉnh/Thành phố
sub_region_idintID Quận/Huyện
sub_sub_region_idintID Phường/Xã
tagstringTag
notestringGhi chú
internal_namestringTên nội bộ
internal_notestringGhi chú nội bộ
salutationstringDanh xưng
address_line_2stringĐịa chỉ phụ
delivery_notestringGhi chú giao hàng
zalo_idstringID Zalo
facebook_idstringID Facebook
instagram_idstringID Instagram
tiktok_idstringID TikTok
shopee_idstringID Shopee
telegram_idstringID Telegram
tax_buyer_namestringTên người mua hàng (hóa đơn)
tax_buyer_addressstringĐịa chỉ (hóa đơn)
tax_buyer_tax_numberstringMã số thuế

Ví dụ JSON

{
    "company_id": 10311,
    "items": [
        { "full_name": "Nguyễn Văn A", "phone": "0901234567", "code": "KH001" },
        { "full_name": "Trần Thị B", "email": "tranthib@example.com", "birthday": "15/08/1995" }
    ]
}

Workflow & Logic

  • Từng dòng được kiểm tra riêng (tên bắt buộc, trùng/định dạng mã, email, số điện thoại, ngày sinh). Dòng lỗi bị bỏ qua, các dòng hợp lệ vẫn được tạo.
  • Người tạo của các khách hàng là user đang gọi API.

Response Schema

HTTP 200 - JSON Object

TrườngKiểuMô tả
success_countintSố khách hàng tạo thành công
error_countintSố dòng lỗi
errorsarrayDanh sách lỗi theo dòng: row (số thứ tự dòng, bắt đầu từ 1) và errors (mảng mã lỗi)
{
    "success_count": 1,
    "error_count": 1,
    "errors": [
        { "row": 2, "errors": ["error_email_exists"] }
    ]
}

Error Codes

HTTPCodeMô tả
403error_role_not_availableKhông có quyền customer.manage
422error_empty_itemsThiếu danh sách items
422error_max_10000_itemsVượt quá 10.000 phần tử

Mã lỗi theo dòng (trong errors[].errors): error_fullname_required, error_code_invalid, error_code_exists, error_email_invalid, error_email_exists, error_phone_invalid, error_phone_exists, error_birthday_format_invalid, error_birthday_invalid, error_add.

On this page