Create a new audience segment based on user properties and behaviors.
Endpoint
POST /audiences
Authentication
Required: Bearer token in Authorization header
Authorization: Bearer YOUR_API_KEY
Request Body
{
"app_id": "app_123",
"name": "Active Premium Users",
"description": "Users with premium plan who were active in the last 7 days",
"criteria": "Users with plan=premium AND last_active within 7 days"
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
app_id | string | Yes | Your application ID |
name | string | Yes | Audience name |
description | string | No | Audience description |
criteria | string | Yes | Natural language criteria for audience segmentation |
Response
{
"success": true,
"audience_id": "aud_789",
"name": "Active Premium Users",
"user_count": 1250,
"created_at": "2024-01-15T10:30:00Z",
"message": "Audience created successfully"
}
Examples
JavaScript
const response = await fetch('https://api.appizer.com/v1/audiences', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
app_id: 'app_123',
name: 'Active Premium Users',
description: 'Users with premium plan who were active in the last 7 days',
criteria: 'Users with plan=premium AND last_active within 7 days'
})
});
const data = await response.json();
console.log(data);
Python
import requests
response = requests.post(
'https://api.appizer.com/v1/audiences',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
json={
'app_id': 'app_123',
'name': 'Active Premium Users',
'description': 'Users with premium plan who were active in the last 7 days',
'criteria': 'Users with plan=premium AND last_active within 7 days'
}
)
print(response.json())
cURL
curl -X POST https://api.appizer.com/v1/audiences \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"app_id": "app_123",
"name": "Active Premium Users",
"description": "Users with premium plan who were active in the last 7 days",
"criteria": "Users with plan=premium AND last_active within 7 days"
}'
Criteria Examples
"Users who completed purchase in the last 30 days""Users with email AND NOT subscribed to newsletter""Users from country=US AND plan=premium""Users who triggered event=app_open more than 10 times""Users with signup_date before 2024-01-01"
Error Responses
| Status Code | Description |
|---|---|
| 400 | Bad Request - Invalid criteria or missing required fields |
| 401 | Unauthorized - Invalid or missing API key |
| 429 | Too Many Requests - Rate limit exceeded |
| 500 | Internal Server Error - Something went wrong on our end |
Best Practices
- Use descriptive audience names
- Write clear criteria using natural language
- Test criteria with small segments first
- Monitor audience size over time
- Update audiences as user behavior changes
- Use audiences for targeted push notifications