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

# 创建受众

> 创建由网站访客、互动用户、类似受众或客户名单组成的 Instagram 自定义受众，用于推广时包含或排除。

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

<ul>
  <li>`website`：Meta 像素在你的网站上看到的人。</li>
  <li>`engagement`：与 Facebook 主页、Instagram 账户或视频互动过的人。</li>
  <li>`lookalike`：与你已有受众相似的人。</li>
  <li>`customerList`：你自己的人员名单，通过[受众成员](https://www.ayrshare.com/docs/apis/ads/instagram/audience-members.md)用哈希标识符填充。</li>
</ul>

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

> [!NOTE]
>
> 在创建或使用任何受众之前，广告账户中拥有角色的人员必须在 `https://business.facebook.com/ads/manage/customaudiences/tos/?act=<ad account id>` 接受一次 Meta 的 Custom Audience 条款。Ayrshare 无法代你接受。在此之前，此端点返回带有 `code: 101` 的 `400`，`details` 会指明账户以及接受条款的页面。[广告账户](https://www.ayrshare.com/docs/apis/ads/instagram/get-ad-accounts.md)会在 `tosAccepted.customAudienceTos` 中显示是否已接受。

> [!WARNING]
>
> Meta 不允许在住房、就业或金融广告中使用类似受众。属于这些[特殊广告类别](https://www.ayrshare.com/docs/apis/ads/instagram/boost-post.md#param-special-ad-categories)之一的推广可以包含或排除网站、互动和客户名单受众，但不能使用类似受众。

## 请求头参数

**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`

## 请求体参数

每种 `type` 都接受以下参数：

**accountId** `string` *required*

要在其上创建受众的广告账户，来自[广告账户](https://www.ayrshare.com/docs/apis/ads/instagram/get-ad-accounts.md)，带或不带 `act_` 前缀均可。

**name** `string` *required*

在 Ads Manager 中显示的名称。

**type** `string` *required*

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

**idempotencyKey** `string`

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

### 网站受众

**pixelId** `string` *required*

其事件用于构建受众的 Meta 像素。

**retentionDays** `number` *required*

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

**urlContains** `array`

仅保留访问包含以下任一字符串的 URL 的记录，例如 `["/pricing"]`。

**event** `string`

仅保留触发了此像素事件的访客，例如 `Purchase` 或自定义事件名称。省略则统计每次访问。

### 互动受众

**source** `string` *required*

互动发生的位置：`page`（Instagram 主页）、`instagram`（Instagram 账户）或 `video`。

**sourceIds** `array` *required*

用于统计互动的主页 ID、Instagram 账户 ID 或视频 ID，以字符串形式提供。

**event** `string` *required*

统计的互动类型。这些值是 Meta 自己的名称，取决于 `source`：

<ul>
  <li>`page`: `page_engaged`, `page_visited`, `page_liked`, `page_messaged`, `page_cta_clicked`, `page_or_post_save`, `page_post_interaction`</li>
  <li>`instagram`: `ig_business_profile_all`, `ig_business_profile_engaged`, `ig_business_profile_visit`, `ig_business_profile_ad_saved`, `ig_user_messaged_business`, `ig_ad_like`, `ig_ad_comment`, `ig_ad_share`, `ig_ad_save`, `ig_ad_cta_click`, `ig_ad_carousel_swipe`, `ig_organic_like`, `ig_organic_comment`, `ig_organic_share`, `ig_organic_save`, `ig_organic_swipe`, `ig_organic_carousel_swipe`</li>
  <li>`video`: `video_watched`, `video_completed`, `video_view_10s`, `video_view_15s`, `video_view_25_percent`, `video_view_50_percent`, `video_view_75_percent`</li>
</ul>

任何其他值都会返回带有 `code: 101` 的 `400`，并列出该来源可用的值。

**retentionDays** `number` *required*

人员在最后一次互动后保留在受众中的天数：`page` 和 `instagram` 为 1 到 730，`video` 为 1 到 365。

### 类似受众

**seedAudienceId** `string` *required*

用于查找相似人员的受众，来自[受众](https://www.ayrshare.com/docs/apis/ads/instagram/get-audiences.md)。Meta 需要其中至少有 100 人。

**ratio** `number` *required*

类似受众的规模，以推广所定位国家人口的整数百分比表示：1（最接近匹配）到 20（最广覆盖）。

**allowInternationalSeeds** `boolean`

当某个国家的种子人员太少时，允许 Meta 从其他国家获取种子人员。默认为 `false`。

类似受众没有自己的国家：人员来自[推广的 `targeting.locations`](https://www.ayrshare.com/docs/apis/ads/instagram/boost-post) 指定的国家。发送 `country` 会返回带有 `code: 101` 的 `400`。Meta 需要几个小时来填充类似受众。

### 客户名单受众

**customerFileSource** `string` (default: USER\_PROVIDED\_ONLY)

名单数据的来源，使用 Meta 的术语：`USER_PROVIDED_ONLY`（由本人提供给你）、`PARTNER_PROVIDED_ONLY`（由合作伙伴提供给你）或 `BOTH_USER_AND_PARTNER_PROVIDED`。

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

```bash cURL theme={"system"}
curl \
-H "Authorization: Bearer API_KEY" \
-H "Content-Type: application/json" \
-X POST https://api.ayrshare.com/api/ads/instagram/audiences \
-d '{"accountId": "1234567890", "name": "Site visitors 30d", "type": "website", "pixelId": "987654321098765", "retentionDays": 30, "urlContains": ["/pricing"]}'
```

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

fetch("https://api.ayrshare.com/api/ads/instagram/audiences", {
      method: "POST",
      headers: {
        "Authorization": `Bearer ${API_KEY}`,
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
    "accountId": "1234567890",
    "name": "Site visitors 30d",
    "type": "website",
    "pixelId": "987654321098765",
    "retentionDays": 30,
    "urlContains": [
      "/pricing"
    ]
  })
    })
      .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": "1234567890",
  "name": "Site visitors 30d",
  "type": "website",
  "pixelId": "987654321098765",
  "retentionDays": 30,
  "urlContains": [
    "/pricing"
  ]
}

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

print(r.json())
```

```json 200: Success theme={"system"}
{
  "status": "success",
  "audience": {
    "id": "23851234567890123",
    "name": "Site visitors 30d",
    "type": "website",
    "size": null,
    "status": { "ready": false, "code": 300, "description": "This audience is still being populated." },
    "created": "2026-10-29T10:05:00.000Z"
  }
}
```

```json 400: Field from another type 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: Terms not accepted 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": "Creating a custom audience needs the Custom Audience terms accepted on ad account act_123456789. A person with a role on the account accepts them at https://business.facebook.com/ads/manage/customaudiences/tos/?act=123456789"
}
```

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


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