> ## Documentation Index
> Fetch the complete documentation index at: https://www.ayrshare.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 建立受眾

> 建立 Snapchat 顧客名單、網站或類似受眾區隔，在透過 Ayrshare 推廣 Snap 時納入或排除。

在 Snapchat 廣告帳戶上建立受眾區隔。支援三種類型，透過 `type` 選擇：

<ul>
  <li>`customerList`：你自己的人員名單，透過[受眾成員](https://www.ayrshare.com/docs/apis/ads/snapchat/audience-members.md)以雜湊識別碼填充。</li>
  <li>`website`：你的 Snap Pixel 在你的網站上記錄到觸發某個事件的人。</li>
  <li>`lookalike`：你指定國家中與你某個顧客名單裡的人相似的人。</li>
</ul>

新區隔會在 `audience` 下回傳，格式與[受眾](https://www.ayrshare.com/docs/apis/ads/snapchat/get-audiences.md)相同，且 `status.ready: false`。Snapchat 會隨時間填充它。列出區隔以查看 `status.ready` 何時變為 `true`，然後在[推廣 Snap](https://www.ayrshare.com/docs/apis/ads/snapchat/boost-post.md#audiences)時，在 `targeting.audiences` 或 `targeting.excludedAudiences` 中使用其 `id`。

<ul>
  <li>Snapchat 比對到足夠多的人後，推廣即可鎖定該區隔。在此之前，`status.ready` 為 `false`。</li>
  <li>一個廣告帳戶最多可有 1,000 個顧客名單，區隔名稱最多 375 個字元。超出時 Snapchat 會以 `code: 369` 拒絕。</li>
  <li>Snapchat 無法在此建立互動受眾。`type: engagement` 會回傳帶有 `code: 101` 的 `400`。</li>
  <li>如果可能重試，請傳送 `idempotencyKey`：使用相同金鑰和相同請求體重試，會回傳第一次的回應，而不會建立第二個區隔。</li>
</ul>

## 請求頭參數

**Authorization** `string` *required*

[API Key](https://www.ayrshare.com/docs/apis/overview.md#authorization) of the Primary Profile.

Format: `Authorization: Bearer API_KEY`
**Profile-Key** `string`

[Profile Key](https://www.ayrshare.com/docs/apis/overview.md#profile-key-format) of a User Profile.

Format: `Profile-Key: PROFILE_KEY`

## 請求體參數

**accountId** `string` *required*

要在其上建立區隔的 Snapchat 廣告帳戶 ID，例如 `5a0d0000-0000-4000-8000-000000000003`。

**name** `string` *required*

在 Snapchat Ads Manager 中顯示的名稱。

**type** `string` *required*

`customerList`、`website` 或 `lookalike`。其他欄位取決於它。

**idempotencyKey** `string`

每個新區隔的唯一值，例如 UUID。

### 顧客名單

沒有其他欄位。名單一開始為空，並會保留人員，直到你將其移除。`customerFileSource` 為選填：Snapchat 名單只包含你自己的資料，因此除 `USER_PROVIDED_ONLY` 外的任何值都會回傳 `code: 101`。

### 網站

**pixelId** `string` *required*

你的 Snap Pixel ID。

**event** `string` *required*

訪客必須觸發過的像素事件，依 Snapchat 的拼寫：`PAGE_VIEW`、`VIEW_CONTENT`、`ADD_CART`、`START_CHECKOUT`、`PURCHASE`、`SIGN_UP`、`SUBSCRIBE`、`SEARCH`、`ADD_TO_WISHLIST`、`CUSTOM_EVENT_1` 到 `CUSTOM_EVENT_5`，或其他 [Snapchat 像素事件](https://developers.snap.com/marketing-api/Ads-API/audience-creation/website-events)。在 Snapchat 上為必填。

**retentionDays** `number` *required*

訪客留在區隔中的天數，範圍為 1 到 180。

Snapchat 不支援 `urlContains`：Snapchat 的網站區隔只依像素事件保留人員，因此會回傳 `code: 101`。

### 類似受眾

**seedAudienceId** `string` *required*

用於尋找相似人群的顧客名單（[受眾](https://www.ayrshare.com/docs/apis/ads/snapchat/get-audiences.md)中的 `type: customerList`）。Snapchat 只能以顧客名單建立類似受眾，因此不是你在此廣告帳戶上的顧客名單的種子（其他類型的區隔、其他帳戶的區隔或已刪除的區隔）會回傳 `code: 101`。

**countries** `array` *required*

要在其中尋找人員的國家，使用兩個字母的代碼，例如 `US`。每個國家只能出現一次。

**similarity** `string`

`balance`（預設）兼顧相似度和規模，`similarity` 保留與種子最相似的人，`reach` 找到最多的人。

**retentionDays** `number`

人員留在區隔中的天數，範圍為 1 到 180。預設為 180。

Snapchat 類似受眾沒有規模百分比：`ratio` 和 `allowInternationalSeeds` 會回傳 `code: 101`。

```bash cURL theme={"system"}
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X POST https://api.ayrshare.com/api/ads/snapchat/audiences \
-d '{"accountId": "5a0d1b2c-0000-4000-8000-000000000003", "type": "lookalike", "name": "Like my subscribers", "seedAudienceId": "8c1e2f3a-0000-4000-8000-000000000101", "countries": ["US", "GB"], "similarity": "balance"}'
```

```javascript JavaScript theme={"system"}
const API_KEY = "API_KEY";

fetch("https://api.ayrshare.com/api/ads/snapchat/audiences", {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${API_KEY}`,
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        accountId: "5a0d1b2c-0000-4000-8000-000000000003",
        type: "lookalike",
        name: "Like my subscribers",
        seedAudienceId: "8c1e2f3a-0000-4000-8000-000000000101",
        countries: ["US", "GB"],
        similarity: "balance"
      })
    })
      .then((res) => res.json())
      .then((json) => console.log(json))
      .catch(console.error);
```

```python Python theme={"system"}
import requests

payload = {
    'accountId': '5a0d1b2c-0000-4000-8000-000000000003',
    'type': 'lookalike',
    'name': 'Like my subscribers',
    'seedAudienceId': '8c1e2f3a-0000-4000-8000-000000000101',
    'countries': ['US', 'GB'],
    'similarity': 'balance'
}
headers = {'Content-Type': 'application/json', 'Authorization': 'Bearer API_KEY'}

r = requests.post('https://api.ayrshare.com/api/ads/snapchat/audiences', json=payload, headers=headers)

print(r.json())
```

```json 200: Success theme={"system"}
{
  "status": "success",
  "audience": {
    "id": "8c1e2f3a-0000-4000-8000-000000000102",
    "name": "Like my subscribers",
    "type": "lookalike",
    "size": { "lower": 0, "upper": 0 },
    "status": { "ready": false, "code": null, "description": "NOT_READY" },
    "created": "2026-12-02T12:00:00.000Z"
  }
}
```

```json 400: A field Snapchat does not take theme={"system"}
{
  "action": "request",
  "status": "error",
  "code": 101,
  "message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
  "details": "ratio is not a recognised field."
}
```

```json 400: Website without an event theme={"system"}
{
  "action": "request",
  "status": "error",
  "code": 101,
  "message": "Missing or incorrect parameters. Please verify with the docs. https://www.ayrshare.com/docs/apis",
  "details": "event is required on snapchat: one of APP_INSTALL, PURCHASE, ..."
}
```

```json 400: Snapchat refused the request theme={"system"}
{
  "action": "ads",
  "status": "error",
  "code": 369,
  "message": "Unable to create the audience. Please try again.",
  "details": "Snapchat's reason"
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.