# Thêm khách vào tệp đối tượng tùy chỉnh

* Thêm khách hàng vào tệp đối tượng tùy chỉnh.

## Request

* Xem [common request params](/v3/readme.md#request-params).

### Params

* `audienceId` lấy được từ API [Tạo tệp đối tượng tùy chỉnh](/v3/vpage/marketing/custom_audience_create.md).
* `dataType` hỗ trợ 2 loại dữ liệu là `raw` hoặc `hash` (dùng hàm hash("sha256", "text")). VD bạn có số điện thoại là 0987654321
  * `raw` = 0987654321
  * `hash` = f9dd5cfd005ea36d8db32ecfb6867c9a22a8e3d7c95e14abcee629e155ebc2b2
* `audienceData` mảng khách hàng, hỗ trợ tối đa 5000 khách hàng / request. Nếu bạn có nhiều dữ liệu, bạn nên gom nhiều khách vào 1 request để tránh lỗi [Facebook Rate Limiting](https://developers.facebook.com/docs/graph-api/overview/rate-limiting/?locale=en_US#custom-audience). VD: Bạn có tệp 100.000 khách hàng, thì bắn lên 20 lần, mỗi lần 5000 khách hàng.
* Một khách hàng có thể gửi tối đa 3 số điện thoại và 3 email, bắt buộc phải có tối thiểu 1 số điện thoại hoặc 1 email. VD:

```
# VD chỉ có số điện thoại
"audienceData": [
  {
    "phone": "0987654321",
  },
  {
    "phone": "0987654322",
  }
]

# VD chỉ có enmail
"audienceData": [
  {
    "email": "vpage.nhanhvn@gmail.com"
  },
  {
    "email": "vpage1.nhanhvn@gmail.com"
  }
]

# VD nhiều số điện thoại, nhiều email
"audienceData": [
  {
    "phone": "0987654321",
    "phone_2": "0987654329",
    "phone_3": "0987654328",
    "email": "vpage.nhanhvn@gmail.com",
    "email_2": "vpage4.nhanhvn@gmail.com"
  }
]
```

### dataType raw

```curl
curl --location 'https://vpage.open.nhanh.vn/v3.0/marketing/customaudienceaddsubscriber?appId={{appId}}&businessId={{businessId}}' \
--header 'Authorization: {{accessToken}}' \
--header 'Content-Type: application/json' \
--data '{
    "audienceId": "{{audienceId}}",
    "dataType": "raw",
    "audienceData": [
        {
          "phone": "0987654321",
          "phone_2": "0987654329",
          "phone_3": "0987654328",
          "email": "vpage.nhanhvn@gmail.com",
          "email_2": "vpage4.nhanhvn@gmail.com"
        },
        {
          "phone": "0987654322",
          "email": "vpage2.nhanhvn@gmail.com",
          "email_2": "vpage3.nhanhvn@gmail.com",
          "email_3": "vpage5.nhanhvn@gmail.com"
        }
    ]
}'
```

### dataType hash

* Chú ý:
  * Email cần convert sang lower case trước khi hash.
  * Phone cần convert về dạng có mã quốc gia phía trước, bỏ hết các ký tự đặc biệt, dấu cách, số 0 ở đầu đi. VD số 0987654321 ở Vietnam (+84), cần chuyển thành 84987654321 trước khi hash.

```curl
curl --location 'https://vpage.open.nhanh.vn/v3.0/marketing/customaudienceaddsubscriber?appId={{appId}}&businessId={{businessId}}' \
--header 'Authorization: {{accessToken}}' \
--header 'Content-Type: application/json' \
--data '{
    "audienceId": "{{audienceId}}",
    "dataType": "hash",
    "audienceData": [
        {
          "phone": "17756315ebd47b7110359fc7b168179bf6f2df3646fcc888bc8aa05c78b38ac1",
          "phone_2": "f9dd5cfd005ea36d8db32ecfb6867c9a22a8e3d7c95e14abcee629e155ebc2b2",
          "phone_3": "bc73d47c6459288d514cc759d417a43a8f3981d1a150dad3b4ab4de0199eac5d",
          "email": "5aa0c39831f6953a69ffd9a275969a563bb4be9900e3ee8e0e34501b37778d27",
          "email_2": "e01c2ae5208665cf7cc8e4bc270a1dcbfdcce629a1ffce1acbb2e4cf6873d6ec"
        },
        {
          "phone": "d88a8cfc6a4483536de276fc6c0b9b906ed26425ca26d6e8dbea33be769f1ac6",
          "email": "c1822e15467e69822503ed226df5b565aeb36005b672b357ee32fc2ee18173b6",
          "email_2": "4af0a859010eca3ea17561a9ed607f873d927767079fa788a09274cdaa9a1c96",
          "email_3": "59d1ecd2696d9b301d78136238014d8a6e4357768daec8569080116b807b3c46"
        }
    ]
}'
```

## Response

* Xem cấu trúc chung [tại đây](/v3/readme.md#response).

### Failed response

* Xem các mã lỗi chung [tại đây](/v3/readme.md#failed-response).

### Successful response

```json
{
  "code": 1,
  "data": [
    {
      "num_received": "(number) số khách hàng đã upload thành công",
    }
  ]
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://apidocs.nhanh.vn/v3/vpage/marketing/custom_audience_addsubscriber.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
