# Custom Audiences

Create a TikTok Custom Audience from a customer list and upload its members by email.

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

Build a customer-file Custom Audience on a `tiktokads` account, then target it through `audienceInclude` or `audienceExclude` ([Targeting fields](/platforms/tiktok-ads/targeting)).

## Create an audience

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

`adAccountId` is the TikTok advertiser id.

TikTok matches on email only (other keys are ignored). Send emails in plaintext (SHA-256 hashed server-side) or already hashed.

The first upload creates the audience on TikTok and each later upload adds to it, so send lists over 10,000 as several uploads. TikTok allows 24 updates per audience per day.

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

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="7123456789012345678",
    type="customer_list",
    name="Cart abandoners",
)

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": "7123456789012345678", "type": "customer_list", "name": "Cart abandoners" }'

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": "Cart abandoners", "type": "customer_list", "platform": "tiktok", "status": "pending" },
  "message": "Audience created"
}
```

Response (`200`):

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

## 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.
- TikTok refuses a removal that would leave the audience under 1,000 people.

## How it behaves

- **The audience is created lazily** on the first member upload, because TikTok needs the member file at creation time.
- The create records it with status `pending` and no platform id. The first `users` call provisions it on TikTok.
- A new audience takes up to 48 hours to finish processing before it is targetable.

## If it fails

| Error | Cause | Fix |
|---|---|---|
| Members not matched | No `email` was sent; TikTok matches on email only | Send an `email` for each member. |
| Audience not targetable | It is still processing, which takes up to 48 hours | Wait, then pass its `platformAudienceId` to `audienceInclude`. |
| No platform id on the audience | No members have been uploaded yet | Upload members: the first upload creates it on TikTok. |

## Related

- [Targeting fields](/platforms/tiktok-ads/targeting): where `audienceInclude` and `audienceExclude` go.
- [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 member upload.