56 lines
1.4 KiB
Plaintext
56 lines
1.4 KiB
Plaintext
---
|
|
title: "Query Usage Data"
|
|
openapi: "coreapi POST /query"
|
|
---
|
|
|
|
This endpoint allows you to query usage data for specific features over various time ranges. It returns historical usage information that can be used for analytics, reporting, or displaying usage graphs to customers.
|
|
|
|
<Tip>
|
|
You can query usage for a single feature or multiple features in one request by passing an array of feature IDs.
|
|
</Tip>
|
|
|
|
<Note>
|
|
The response returns a list of objects. Each object includes a `period` timestamp and one key per requested feature ID with its usage value.
|
|
</Note>
|
|
|
|
{/*
|
|
## Example Usage
|
|
|
|
### Single Feature Query
|
|
|
|
Query usage for the "messages" feature over the last 30 days:
|
|
|
|
```javascript
|
|
const response = await autumn.query({
|
|
customer_id: 'user_123',
|
|
feature_id: 'messages',
|
|
range: '30d'
|
|
});
|
|
|
|
console.log(response.list);
|
|
// [
|
|
// { period: 1672531200000, messages: 45 },
|
|
// { period: 1672617600000, messages: 32 },
|
|
// { period: 1672704000000, messages: 18 }
|
|
// ]
|
|
```
|
|
|
|
### Multiple Features Query
|
|
|
|
Query usage for both "credits" and "messages" features over the last 7 days:
|
|
|
|
```javascript
|
|
const response = await autumn.query({
|
|
customer_id: 'user_123',
|
|
feature_id: ['credits', 'messages'],
|
|
range: '7d'
|
|
});
|
|
|
|
console.log(response.list);
|
|
// [
|
|
// { period: 1672531200000, credits: 20, messages: 45 },
|
|
// { period: 1672617600000, credits: 15, messages: 32 },
|
|
// { period: 1672704000000, credits: 30, messages: 18 }
|
|
// ]
|
|
``` */}
|