Skip to content

KPI Module

The SAFE Billing Platform KPI (Key Performance Indicators) module provides real-time business intelligence data about your billing operations. Access comprehensive metrics about customers, numbers, features, invoices, payments, Direct Debit collections and outstanding debt through a simple REST API.

The KPI module is designed to integrate seamlessly with your existing business intelligence tools and workflows:

Dashboard Integration

  • Fetch JSON data to populate real-time dashboards (Grafana, PowerBI, Tableau)
  • Set up automated polling to keep metrics current
  • Combine multiple KPIs to create comprehensive business views

Automated Reporting

  • Schedule daily/weekly CSV exports for spreadsheet analysis
  • Track performance trends over time with automated scripts
  • Generate alerts when metrics exceed thresholds

Quick Browser Checks

  • Use HTML output to quickly view KPIs in your browser
  • Share read-only KPI links with team members
  • Bookmark specific KPI views for regular monitoring

Daily Revenue Report Script

#!/bin/bash
# Download yesterday's invoice breakdown as CSV
curl -X GET "https://companyname.callstats.net/backend/kpi/invoices/breakdown/?outputMode=csv" \
-H "Authorization: Bearer YOUR_KPI_KEY" \
> "revenue_$(date +%Y%m%d).csv"

Dashboard JSON Feed

// Fetch customer metrics every 5 minutes for dashboard
setInterval(async () => {
const response = await fetch('https://companyname.callstats.net/backend/kpi/customers/', {
headers: { 'Authorization': 'Bearer YOUR_KPI_KEY' }
});
const data = await response.json();
updateDashboard(data);
}, 300000);

Browser Bookmark

https://companyname.callstats.net/backend/kpi/invoices/byMonth/?key=YOUR_KPI_KEY

Save this URL to quickly check monthly billing trends in your browser.

The KPI module offers aggregated data and insights across seven categories:

  • Customers - Monitor customer counts, status distributions, and dealer performance
  • Numbers - Track telephone number allocations, types, and utilisation
  • Features - Analyse feature adoption, revenue generation, and charge summaries
  • Invoices - Review billing performance, revenue trends, and payment status
  • Payments - Report amounts actually received, by method, dealer and period
  • Collections - Measure Direct Debit and card collection performance, including failures and retries
  • Debt Ageing - Bucket outstanding invoice balances by how overdue they are

Customers, numbers and features can also produce growth and churn series, showing additions and losses over time. See Available KPIs for the full list.

All KPI endpoints require authentication using a valid KPI access key. You can authenticate using either method:

Terminal window
curl -X GET https://companyname.callstats.net/backend/kpi/customers/ \
-H "Authorization: Bearer YOUR_KPI_KEY"
Terminal window
curl -X GET "https://companyname.callstats.net/backend/kpi/customers/?key=YOUR_KPI_KEY"

The KPI module is accessed through your platform’s domain:

https://companyname.callstats.net/backend/kpi/

Replace companyname with your actual platform subdomain.

KPI endpoints use a RESTful URL structure:

/backend/kpi/{object}/
/backend/kpi/{object}/{kpi}/

Where:

  • {object} is the KPI category: customers, numbers, features, invoices, payments, directDebitCollections, cardCollections, or arAgeing
  • {kpi} is the specific KPI type (optional, defaults to summary)
ParameterTypeRequiredDescription
outputModestringNoResponse format: json, csv, or html
keystringConditionalKPI key if not using Bearer authentication
groupBystringNoComma-separated dimensions to group by, instead of a {kpi} type
intervalstringNoPeriod bucket: day, week, month, quarter, or year
measuresstringNoNamed measure set to return (defaults to default)

Every KPI category can be grouped by any of its dimensions using the groupBy parameter, as an alternative to the named KPI types. Combine it with interval to bucket results by time period:

Terminal window
# Payment totals by quarter and payment method
curl -X GET "https://companyname.callstats.net/backend/kpi/payments/?groupBy=period,method&interval=quarter" \
-H "Authorization: Bearer YOUR_KPI_KEY"
  • groupBy accepts a comma-separated list of the category’s dimensions. Each category page lists its dimensions.
  • interval controls the size of the period dimension’s buckets: day, week, month, quarter, or year. If you group by period without an interval, it defaults to month.
  • interval also works with the named KPI types, so invoices/byMonth/?interval=quarter re-buckets the familiar monthly report by quarter.
  • measures selects a named set of result columns where a category offers more than one (for example the invoices breakdown set).

Grouped period columns are named {prefix}period in JSON output (for example invoice_period), except in the legacy byMonth KPI types, which keep their original {prefix}month names.

Summary KPI

Terminal window
curl -X GET "https://companyname.callstats.net/backend/kpi/customers/" \
-H "Authorization: Bearer YOUR_KPI_KEY"

Specific KPI

Terminal window
curl -X GET "https://companyname.callstats.net/backend/kpi/customers/byStatus/" \
-H "Authorization: Bearer YOUR_KPI_KEY"

JSON responses return an array of objects with field names prefixed by the KPI type:

[
{
"customer_count": 2847
}
]

For multi-row results:

[
{
"customer_status": "Active",
"customer_count": 2650
},
{
"customer_status": "Suspended",
"customer_count": 47
}
]

CSV output includes headers and is suitable for spreadsheet import:

Customer Status,Count
Active,2650
Suspended,47

HTML output displays results in a formatted table, ideal for browser viewing:

Customer StatusCount
Active2650
Suspended47

Many KPIs support filtering to refine results. Common filters include:

FilterTypeDescriptionExample
activebooleanOnly include entries with an active statusactive=true
droppedbooleanOnly include entries with an inactive statusdropped=true
dealerCodestringFilter by specific dealerdealerCode=DEALER01
minDatedateEntries dated on or after this dateminDate=2026-01-01
maxDatedateEntries dated on or before this datemaxDate=2026-01-31
customerIDintegerOnly include entries for one customercustomerID=1234
createdSincedateOnly include entries created since this date/timecreatedSince=2026-01-01
updatedSincedateOnly include entries modified since this date/timeupdatedSince=2026-01-01
idAfterintegerOnly include entries with an ID greater than this valueidAfter=1000

Each category page lists exactly which filters it supports. KPI requests also accept the API’s generic field filters (f[field]=value and f[field][operator]=value); see Filtering in the API Reference for the full syntax.

The limit, offset and orderBy list parameters do not apply to KPI results. Row ordering is fixed by the requested dimensions.

Terminal window
curl -X GET "https://companyname.callstats.net/backend/kpi/customers/byDealer/?active=true" \
-H "Authorization: Bearer YOUR_KPI_KEY"

The KPI module returns standard HTTP status codes:

Status CodeDescription
200Success - Request processed successfully
400Bad Request - Invalid parameters or request format
401Unauthorised - Missing or invalid KPI key
403Forbidden - Valid key but insufficient permissions
404Not Found - Invalid object or KPI type
500Server Error - Internal processing error

JSON Format

{
"errors": {
"error": "Invalid KPI type",
"error_code": 400001,
"hint": "Valid KPI types for customers are: null, byStatus, byDealer"
}
}

HTML Format

Error: Invalid KPI type
Error Code: 400001
Hint: Valid KPI types for customers are: null, byStatus, byDealer

KPI endpoints are subject to rate limiting to ensure platform stability. Monitor response headers for current limits and adjust request frequency accordingly.

KPI data is updated in real-time as changes occur in the platform:

  • Customer/Number/Feature KPIs: Real-time updates
  • Invoice KPIs: Updated as invoices are generated, sent, or paid
  • Financial summaries: Calculated on-demand for accuracy
  1. Cache responses appropriately - KPI data changes less frequently than transactional data
  2. Use specific KPIs - Request only the data you need rather than parsing general summaries
  3. Implement retry logic - Handle rate limits and temporary errors gracefully
  4. Monitor rate limit headers - Adjust request frequency based on remaining allowance
  5. Use filters - Reduce data transfer and processing by filtering at the source

Explore the detailed documentation for each KPI category: