> ## 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.