Revenue API
Overview
The RevenueMetrics API allows you to retrieve performance data for websites and ad units over a specific date range. This data includes key metrics such as revenue, impressions, clicks, and other performance indicators, providing actionable insights for optimizing ad performance.
API Details:
API Endpoint
Authentication
Access to the API requires an API key. This key can be obtained in the Universal Developer Portal. Once obtained, the key must be included in the HTTP request header under the field x-api-key
.
Auth Type: API Key
Header Name: x-api-key
Usage Example:
x-api-key: YOUR_API_KEY
Replace the string YOUR_API_KEY
in the code with your actual API key
Request Parameters
Parameter
Type
Required
Description
dateFrom
string
✅ Yes
Start date (format: YYYY-MM-DD HH:MM:SS)
dateTo
string
✅ Yes
End date (format: YYYY-MM-DD HH:MM:SS)
GraphQL Query Example
The following GraphQL query retrieves performance metrics for websites and ad units within a specified date range.
Request Example:
query RevenueMetrics {
revenueMetrics(
where: {
dateFrom: "2024-12-31 00:00:00",
dateTo: "2024-12-31 23:59:59"
}
) {
total
items {
siteId
siteName
adunitId
adunitName
impressions
clicks
revenue
ecpm
arpdau
dau
}
}
}
Below are practical examples of how to send requests to the Revenue Metrics API using various popular programming languages, such as Node.js, Python, and C#. These examples demonstrate how to structure your requests, authenticate using an API key, and handle responses effectively.
const fetch = require('node-fetch');
async function FetchRevenueMetrics(apiKey, dateFrom, dateTo) {
const url = "https://public-api.myappfree.com/graphql/index.html";
const headers = {
"x-api-key": apiKey,
"Content-Type": "application/json"
};
const query = {
query: `
query RevenueMetrics($fromDate: String!, $toDate: String!) {
revenueMetrics(where: { dateFrom: $fromDate, dateTo: $toDate }) {
total
items {
siteId
siteName
adunitId
adunitName
impressions
clicks
revenue
ecpm
arpdau
dau
}
}
}`,
variables: {
fromDate: dateFrom,
toDate: dateTo
}
};
const response = await fetch(url, {
method: "POST",
headers: headers,
body: JSON.stringify(query)
});
if (response.ok) {
const data = await response.json();
return data;
} else {
throw new Error(`Query failed with status ${response.status}: ${await response.text()}`);
}
}
// Usage example
const apiKey = "YOUR_API_KEY";
const dateFrom = "2025-01-10 00:00:00";
const dateTo = "2025-01-10 10:00:00";
FetchRevenueMetrics(apiKey, dateFrom, dateTo)
.then(data => {
console.log("Revenue Metrics:");
console.log(JSON.stringify(data, null, 2)); // Pretty print the response with indentation
})
.catch(err => console.error("Error:", err));
Response Example
Successful Response (200 OK)
If your request is successful, the response will follow this JSON structure:
{
"data": {
"revenueMetrics": {
"total": 1,
"items": [
{
"siteId": 123,
"siteName": "Example Site",
"adunitId": 456,
"adunitName": "Top Banner",
"impressions": 10000,
"clicks": 500,
"revenue": 1500.50,
"ecpm": 15.05,
"arpdau": 3.25,
"dau": 500
}
]
}
}
}
Key Response Fields
Below is a table summarizing key fields returned in the API responses. This will help you interpret and use the data effectively in your application.
Field
Type
Description
total
number
Total item returned
siteId
integer
Unique identifier for the site
siteName
string
Name of the site
adunitId
integer
Unique identifier for the ad unit
adunitName
string
Name of the ad unit
impressions
integer
Total ad impressions
clicks
integer
Total ad clicks
revenue
number
Total revenue generated
ecpm
number
Effective cost per mille
arpdau
number
Average revenue per daily active user
dau
integer
Daily active users
Error Response Examples
When interacting with the API, you may encounter errors if the request is not properly formatted or authorized. This section highlights common issues, their causes, and how to resolve them. Below are examples of typical error responses and what they indicate.
1. Invalid Date Range:
{
"errors": [
{
"message": "Property DateFrom must be earlier than or equal to DateTo. Please correct the date range.",
"locations": [
{
"line": 2,
"column": 5
}
],
"path": [
"revenueMetrics"
]
}
],
"data": {
"revenueMetrics": null
}
}
2. Syntax or Time Range Error:
{
"errors": [
{
"message": "Property DateTo should be in the format yyyy-MM-dd HH:mm:ss. Please correct it.",
"locations": [
{
"line": 2,
"column": 5
}
],
"path": [
"revenueMetrics"
]
}
],
"data": {
"revenueMetrics": null
}
}
3. Invalid API Key:
{
"errors": [
{
"message": "The current user is not authorized to access this resource.",
"locations": [
{
"line": 2,
"column": 5
}
],
"path": [
"revenueMetrics"
],
"extensions": {
"code": "AUTH_NOT_AUTHORIZED"
}
}
],
"data": {
"revenueMetrics": null
}
}
Last updated