Get Current Project Usage by User
Use this endpoint to retrieve how much data each user (identified by username) has consumed in a specific TURN Server project during the current billing cycle. You can authenticate by providing either the secretKey
(for your entire application) or the projectApiKey
(for a specific project).
GET
https://<appname>.metered.live/api/v2/turn/project/:projectId/current_usage_by_user
<appname>
- Replace with the name of your app.
:projectId
- The unique ID of the project whose user-level usage you want to retrieve.
Request
GET /api/v2/turn/project/:projectId/current_usage_by_user
Path Parameter
Parameter | Description | Data Type |
---|---|---|
projectId | The unique ID of the project (must be a valid ObjectId) | String |
Query Parameters (Authentication)
Parameter | Description | Data Type |
---|---|---|
secretKey | Your application's secret key, found in Dashboard → Developers → Secret Key. Only one of secretKey or projectApiKey is required. | String |
projectApiKey | The API key for the specific project. Only one of secretKey or projectApiKey is required. | String |
Other Query Parameters
Parameter | Description | Data Type |
---|---|---|
page | Page number for pagination (default 1 ). Each page contains up to 25 records. | Number |
Example:
GET /api/v2/turn/project/:projectId/current_usage_by_user?secretKey=<YOUR_SECRET_KEY>&page=2
Retrieves the second page of the user usage data for the specified project.
Responses
Success Response
Returns a JSON object containing the following fields:
Field | Description | Data Type |
---|---|---|
data | An array of objects, each representing a user’s usage data. | Array |
has_more | A boolean indicating whether more records exist beyond the current page . | Boolean |
Each object in the data
array includes:
Field | Description | Data Type |
---|---|---|
label | The label associated with the credential (if any). | String or null |
username | The TURN username for which usage is being reported. | String |
usageInBytes | The total usage (in bytes) for this user during the current billing cycle. May be returned as a string; parse as needed. | String |
HTTP Status: 200 OK
Example Success Response
{
"data": [
{
"label": "test",
"username": "c7e21d0a812c0c3fdb3af925",
"usageInBytes": "459269410"
}
],
"has_more": false
}
Error Responses
HTTP Status | Message | Description |
---|---|---|
400 | Invalid request. Not subscribed to any turn server plan | The application is not subscribed to a TURN server plan. |
400 | Project not found | The specified project does not exist or does not match the provided secretKey or projectApiKey . |
Code Examples
cURL
curl -X GET "https://<appname>.metered.live/api/v2/turn/project/63fdb9f998c1abec0bd3e16c/current_usage_by_user?secretKey=<YOUR_SECRET_KEY>&page=1"
JavaScript (Fetch)
fetch(`https://<appname>.metered.live/api/v2/turn/project/63fdb9f998c1abec0bd3e16c/current_usage_by_user?projectApiKey=<PROJECT_API_KEY>&page=1`)
.then(response => response.json())
.then(data => {
console.log("User Usage Data:", data.data);
console.log("Has More Pages?", data.has_more);
})
.catch(error => console.error("Error:", error));