Run custom analytics queries on your event data using natural language or SQL.
Endpoint
POST /analytics/query
Authentication
Required: Bearer token in Authorization header
Authorization: Bearer YOUR_API_KEY
Request Body
{
"query": "Show me total purchases by day for the last 30 days",
"app_id": "app_123"
}
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
query | string | Yes | Natural language or SQL query |
app_id | string | Yes | Your application ID |
format | string | No | Response format: json (default) or csv |
Response
{
"success": true,
"data": [
{
"date": "2024-01-01",
"total_purchases": 45
},
{
"date": "2024-01-02",
"total_purchases": 52
}
],
"query_time_ms": 123,
"rows_returned": 30
}
Examples
JavaScript
const response = await fetch('https://api.appizer.com/v1/analytics/query', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: 'Show me total purchases by day for the last 30 days',
app_id: 'app_123'
})
});
const data = await response.json();
console.log(data);
Python
import requests
response = requests.post(
'https://api.appizer.com/v1/analytics/query',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
json={
'query': 'Show me total purchases by day for the last 30 days',
'app_id': 'app_123'
}
)
print(response.json())
cURL
curl -X POST https://api.appizer.com/v1/analytics/query \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"query": "Show me total purchases by day for the last 30 days",
"app_id": "app_123"
}'
Natural Language Query Examples
- "Show me total revenue by month"
- "How many users signed up last week?"
- "What are the top 10 events by count?"
- "Show me daily active users for the last 7 days"
- "What's the conversion rate from signup to purchase?"
Error Responses
| Status Code | Description |
|---|---|
| 400 | Bad Request - Invalid query or missing required fields |
| 401 | Unauthorized - Invalid or missing API key |
| 429 | Too Many Requests - Rate limit exceeded (100 requests/minute) |
| 500 | Internal Server Error - Something went wrong on our end |
Rate Limits
- 100 requests per minute
Best Practices
- Use specific date ranges for better performance
- Cache query results when possible
- Use natural language for ad-hoc queries
- Consider using pre-calculated metrics for frequently accessed data
- Monitor query performance and optimize slow queries