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