Skip to main content

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

ParameterDescriptionData Type
projectIdThe unique ID of the project (must be a valid ObjectId)String

Query Parameters (Authentication)

ParameterDescriptionData Type
secretKeyYour application's secret key, found in Dashboard → Developers → Secret Key. Only one of secretKey or projectApiKey is required.String
projectApiKeyThe API key for the specific project. Only one of secretKey or projectApiKey is required.String

Other Query Parameters

ParameterDescriptionData Type
pagePage 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:

FieldDescriptionData Type
dataAn array of objects, each representing a user’s usage data.Array
has_moreA boolean indicating whether more records exist beyond the current page.Boolean

Each object in the data array includes:

FieldDescriptionData Type
labelThe label associated with the credential (if any).String or null
usernameThe TURN username for which usage is being reported.String
usageInBytesThe 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 StatusMessageDescription
400Invalid request. Not subscribed to any turn server planThe application is not subscribed to a TURN server plan.
400Project not foundThe 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));