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

# 创建受众

> 使用您自己的客户名单或网站访客创建 Reddit 自定义受众，用于在推广帖子时包含或排除。

在 Reddit 广告账户上创建自定义受众。支持两种类型，通过 `type` 选择：

<ul>
  <li>`customerList`：您自己的人员名单，通过[受众成员](https://www.ayrshare.com/docs/apis/ads/reddit/audience-members.md)用哈希标识符填充。</li>
  <li>`website`：您的 Reddit 像素在您的网站上看到的人。</li>
</ul>

新受众以与[受众](https://www.ayrshare.com/docs/apis/ads/reddit/get-audiences.md)相同的结构在 `audience` 下返回，`status.ready: false`。Reddit 会逐步填充它。列出受众以查看 `status.ready` 何时变为 `true`，然后在[推广帖子](https://www.ayrshare.com/docs/apis/ads/reddit/boost-post.md#audiences)时将其 `id` 用于 `targeting.audiences` 或 `targeting.excludedAudiences`。

<ul>
  <li>Reddit 无法在此创建互动受众或类似受众。发送 `type: engagement` 或 `type: lookalike` 会返回带有 `code: 101` 的 `400`。</li>
  <li>受众需要至少匹配 1,000 人，推广才能定位它。</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*

您的 Reddit 广告账户 ID，例如 `a2_abc123`。

**name** `string` *required*

在 Reddit Ads Manager 中显示的名称。

**type** `string` *required*

`customerList` 或 `website`。每种类型只接受下方列出的自身字段。来自其他类型的字段会返回带有 `code: 101` 的 `400` 并指明该字段。

**idempotencyKey** `string`

为每个新受众提供一个新的唯一值，例如 UUID。如果您用相同的键重复请求，Ayrshare 会返回第一次的响应，并标记 `idempotentReplayed: true`，不会创建第二个受众。您也可以改为在 `Idempotency-Key` 请求头中发送该键；如果两者都发送，它们必须一致。将键用于不同的请求，或在第一个请求仍在处理时重用该键，会返回 `409`。`503` 表示无法预留该键且未创建任何内容：请稍后使用相同的键重试。

### 客户名单受众

客户名单没有其他必填字段，创建时为空。使用[受众成员](https://www.ayrshare.com/docs/apis/ads/reddit/audience-members.md)添加人员。哈希标识符仍然是个人数据：上传名单前请阅读该页面。

在 Reddit 上，`customerFileSource` 只接受 `USER_PROVIDED_ONLY`：Reddit 只接受您自己的名单。

### 网站受众

**pixelId** `string` *required*

您的 Reddit 像素 ID，可在 Reddit Ads Events Manager 中找到。

**retentionDays** `number` *required*

访客在最后一次访问后保留在受众中的天数，1 到 90。

**event** `string`

仅保留触发了此事件的访客。Reddit 的标准事件为 `PAGE_VISIT`、`VIEW_CONTENT`、`SEARCH`、`ADD_TO_CART`、`ADD_TO_WISHLIST`、`PURCHASE`、`LEAD` 和 `SIGN_UP`，大小写均可。任何其他值都会作为自定义事件名称发送。省略则统计每次访问。

Reddit 不接受 `urlContains`：Reddit 的网站受众没有 URL 筛选条件。

```bash cURL theme={"system"}
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X POST https://api.ayrshare.com/api/ads/reddit/audiences \
-d '{"accountId": "a2_abcdefg", "name": "Site visitors 30d", "type": "website", "pixelId": "t2_pixel123", "retentionDays": 30, "event": "purchase"}'
```

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

fetch("https://api.ayrshare.com/api/ads/reddit/audiences", {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${API_KEY}`,
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
    "accountId": "a2_abcdefg",
    "name": "Site visitors 30d",
    "type": "website",
    "pixelId": "t2_pixel123",
    "retentionDays": 30,
    "event": "purchase"
  })
    })
      .then((res) => res.json())
      .then((json) => console.log(json))
      .catch(console.error);
```

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

headers = {'Authorization': 'Bearer API_KEY', 'Content-Type': 'application/json'}
payload = {
  "accountId": "a2_abcdefg",
  "name": "Site visitors 30d",
  "type": "website",
  "pixelId": "t2_pixel123",
  "retentionDays": 30,
  "event": "purchase"
}

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

print(r.json())
```

```json 200: Success theme={"system"}
{
  "status": "success",
  "audience": {
    "id": "ca.129482487242999",
    "name": "Site visitors 30d",
    "type": "website",
    "size": null,
    "status": { "ready": false, "code": null, "description": "PENDING" },
    "created": "2026-12-02T10:05:00.000Z"
  }
}
```

```json 400: Lookback over 90 days 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": "retentionDays on reddit is at most 90."
}
```

```json 400: Reddit refused the request 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": "Reddit's reason"
}
```

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


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