# Tailored Audiences

Create a Tailored Audience on an X Ads account and upload its members by email.

import { Tab, Tabs } from 'fumadocs-ui/components/tabs';

A Tailored Audience is an X `customer_list` audience: you create it, then upload the emails of the people in it.

## Create an audience

Create the audience with `POST /v1/ads/audiences` (`type: "customer_list"`), then upload members with `POST /v1/ads/audiences/{audienceId}/users`.

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">
```typescript
const { data: audience } = await zernio.adaudiences.createAdAudience({
  body: {
    accountId: '66b2e19d8c3f5a7e9d0b1c2d',
    adAccountId: '18ce54d4x5t',
    type: 'customer_list',
    name: 'Trial signups'
  }
});

const { data: upload } = await zernio.adaudiences.addUsersToAdAudience({
  path: { audienceId: audience.audience.id },
  body: { users: [{ email: 'jane@example.com' }, { email: 'sam@example.com' }] }
});

console.log(upload.numReceived);
```
</Tab>
<Tab value="Python">
```python
audience = client.ad_audiences.create_ad_audience(
    account_id="66b2e19d8c3f5a7e9d0b1c2d",
    ad_account_id="18ce54d4x5t",
    type="customer_list",
    name="Trial signups",
)

upload = client.ad_audiences.add_users_to_ad_audience(
    audience_id=audience["audience"]["id"],
    users=[{"email": "jane@example.com"}, {"email": "sam@example.com"}],
)

print(upload["numReceived"])
```
</Tab>
<Tab value="curl">
```bash
curl -X POST "https://zernio.com/api/v1/ads/audiences" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "accountId": "66b2e19d8c3f5a7e9d0b1c2d", "adAccountId": "18ce54d4x5t", "type": "customer_list", "name": "Trial signups" }'

curl -X POST "https://zernio.com/api/v1/ads/audiences/66e5b2c3d4f5a6b7c8d9e0f1/users" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "users": [{ "email": "jane@example.com" }, { "email": "sam@example.com" }] }'
```
</Tab>
</Tabs>

Response (`201`):

```json
{
  "audience": { "id": "66e5b2c3d4f5a6b7c8d9e0f1", "name": "Trial signups", "type": "customer_list", "platform": "twitter", "status": "pending" },
  "message": "Audience created"
}
```

Response (`200`):

```json
{ "message": "Users added", "numReceived": 2, "numInvalid": 0 }
```

Target it by passing its X custom audience id in `audienceInclude` or `audienceExclude` ([Targeting fields](/platforms/x-ads/targeting)).

## Remove users

When someone leaves your list, call `DELETE /v1/ads/audiences/{audienceId}/users` with the same body as the upload, up to 10,000 users per request. Each row removes the person it added.

```bash
curl -X DELETE "https://zernio.com/api/v1/ads/audiences/66e5b2c3d4f5a6b7c8d9e0f1/users" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "users": [{ "email": "sam@example.com" }] }'
```

- A row without an email counts in `invalid`. A request with no email at all returns 400.
- X removes them in the background, so the audience size drops later.

## How it behaves

- X matches on email and ignores every other key.
- Send emails in plaintext (SHA-256 hashed before they leave) or already hashed.
- One upload takes at most 10,000 users and adds to the audience, so send larger lists as several uploads.
- An audience must match at least 100 recently active users before X allows targeting against it, so its size reads as 0 until then.
- `customer_list` is the only audience type on X.

## If it fails

| Error | Cause | Fix |
|-------|-------|-----|
| `422` with code `feature_not_available` | An audience type other than `customer_list` | Create a `customer_list` audience. |
| `400` on the upload | An empty `users` array, or a user with no match key | Send at least one user with an email. |
| `422` on the upload | The audience is not a `customer_list`, or has no X id yet | Upload to a `customer_list` audience that has finished creating. |
| `409` with code `ads_connection_required` | The `xads` account is inactive or needs reconnection | [Reconnect](/platforms/x-ads#connect) it, then retry. |

## Related

- [Create ad audience](/ad-audiences/create-ad-audience): every field of the create.
- [Add users to ad audience](/ad-audiences/add-users-to-ad-audience): the upload and its limits.
- [Targeting fields](/platforms/x-ads/targeting): target or exclude the audience.
- [Create a campaign](/platforms/x-ads/create-ads): the request that carries `audienceInclude`.