The Xagle Stats API
The Stats API answers one question per call with one number: how many leads did we add in March, what did we invoice last quarter, how much did we collect by card this week. It is built for spreadsheet cells, dashboard tiles and reporting tools that want a figure, not a list of records. Every figure is calculated live from the same data the in-app lists and reports use.
All endpoints require authentication: POST /api/v1/login with email + password returns {"token": "..."}; pass it as Authorization: Bearer {token} on every call. Responses follow the standard envelope: {"success": true, "message": "...", "data": ...} on success, {"success": false, "message": "..."} on failure, and {"errors": {field: [...]}} with HTTP 422 on validation failure.
Status codes: 200 figure returned, 422 validation failure (unknown stat, unsupported aggregate, bad dates, bad filter value), 403 the token's user does not have the view permission for the module the stat reads, 400 the figure could not be calculated.
Permissions: each stat names the module permission it needs (for example invoices.view). Admin tokens can ask for every stat. A standard user's token can ask only for stats whose module that user can view in the app. GET /api/v1/stats/catalog reports a permitted flag per stat for the calling token.
Endpoints
| Operation | Endpoint |
|---|---|
| Get one figure | GET /api/v1/stats (parameters in the query string) or POST /api/v1/stats (parameters as JSON) |
| List the available stats | GET /api/v1/stats/catalog |
| Legacy path | GET or POST /api/v1/stats/get-stats, identical to /api/v1/stats. Kept for spreadsheets built against the original 2022 endpoint; the old stat_type parameter name is accepted as an alias of stat. |
Parameters
Every request takes these:
| Parameter | Required | Meaning |
|---|---|---|
stat | yes | Which figure to calculate. One of the names in the catalog below. |
from | yes | First day of the period, inclusive. YYYY-MM-DD is preferred; any parseable date works, and a date with a time (for example the ISO string a Google Sheets date serialises to) is reduced to its calendar day. |
to | yes | Last day of the period, inclusive. Must not be before from. |
aggregate | no | count (default), sum, avg or quantity. Each stat lists which it supports; asking for an unsupported one returns 422 with the supported list in the message. |
Plus the filters the chosen stat accepts (next section). Filters not listed for a stat are ignored. The response echoes the filters that were actually applied under meta.filters.
Stats catalog
Which day a record falls on: invoices, quotes, expenses and item sales use the document date (invoice date, quote date, expense date). Payments use the date received. New clients and recurring invoice profiles use the date they were created. Client conversions and status changes use the day the change happened.
| Stat | Counts / sums | Aggregates | Filters | Permission |
|---|---|---|---|---|
new_clients | Clients created in the period. client_type is matched against the type the client had when it was created, so a lead that was later converted still counts as a new lead. | count | client_type (lead, prospect, customer, affiliate, trial, other, referral_partner, integration_partner, corporate) | clients.view |
converted_clients | Client type changes in the period, for example lead to prospect or prospect to customer. | count | converted_to (required), converted_from (optional; any type when omitted) | clients.view |
inactive_clients | Clients made inactive in the period (customers lost). | count | none | clients.view |
reactivated_clients | Inactive clients made active again in the period. | count | none | clients.view |
invoices | Invoices by invoice date. Credit memos and refunds are not included. sum and avg use the invoice measure in base currency. | count, sum, avg | status (all, draft, sent, viewed, paid, unpaid, overdue, canceled, refunded, mailed, emailed; default all), measure (total, paid, balance; default total), client_id, invoice_tags, client_tags | invoices.view |
quotes | Quotes by quote date. sum and avg use the quote total in base currency. | count, sum, avg | status (all, draft, sent, viewed, approved, rejected, canceled; default all), client_id, quote_tags, client_tags | quotes.view |
recurring_invoices | Recurring invoice profiles created in the period. sum and avg use the profile total in base currency. | count, sum, avg | client_id | recurring_invoices.view |
payments | Payments by the date received. Credit memo refunds are not payments and are left out. sum and avg are in base currency. | count, sum, avg | payment_method (the method's name as shown in Xagle), client_id | payments.view |
expenses | Recorded expenses by expense date. Forecast rows are projections and are left out. | count, sum, avg | category (the category's name), vendor_id, client_id | expenses.view |
item_sales | Invoice lines by invoice date. Drafts and canceled invoices are not sales and are left out; convenience-fee lines are not items. count is the number of lines, quantity the units sold, sum the pre-tax line subtotal in base currency. | count, quantity, sum | item_master_id, sku (exact), item_name (contains), client_id, include_drafts (1 to include draft invoices; canceled never count) | invoices.view |
Invoice statuses are the same ones the Invoices list filters on, including the calculated ones: paid means fully paid, unpaid means sent with a balance, overdue means unpaid and past its due date as of today, sent means sent and not yet paid.
Money: every sum and avg is in your company base currency. Each record is converted at the exchange rate recorded on it, the same rule the Reports use. meta.currency names the currency on money responses and is null on counts and quantities. Amounts are rounded to your company's amount decimals.
Examples
Invoiced total for March 2026, paid invoices only:
GET /api/v1/stats?stat=invoices&aggregate=sum&status=paid&from=2026-03-01&to=2026-03-31
{
"success": true,
"message": "Record retrieved successfully",
"data": 48210.75,
"meta": {
"stat": "invoices",
"aggregate": "sum",
"from": "2026-03-01",
"to": "2026-03-31",
"filters": {"status": "paid"},
"currency": "USD"
}
}
The figure is always data, as a plain number: an integer for counts, a decimal for sums, averages and quantities. Everything else about the request is echoed under meta.
New leads in a period, sent as JSON:
POST /api/v1/stats
{"stat": "new_clients", "from": "2026-03-01", "to": "2026-03-31", "client_type": "lead"}
Leads that became prospects:
GET /api/v1/stats?stat=converted_clients&converted_from=lead&converted_to=prospect&from=2026-03-01&to=2026-03-31
Units of one item sold, by SKU:
GET /api/v1/stats?stat=item_sales&aggregate=quantity&sku=WDG-100&from=2026-01-01&to=2026-12-31
Card payments collected this quarter:
GET /api/v1/stats?stat=payments&aggregate=sum&payment_method=Credit%20Card&from=2026-07-01&to=2026-09-30
An unsupported aggregate:
GET /api/v1/stats?stat=new_clients&aggregate=sum&from=2026-03-01&to=2026-03-31
HTTP 422
{"errors": {"aggregate": ["Aggregate \"sum\" is not supported for new_clients. Supported: count."]}}
Google Sheets
Paste this into a sheet's Apps Script project (Extensions, Apps Script), set XAGLE_URL and XAGLE_TOKEN, and any cell can call it. The token comes from POST /api/v1/login; keep it in the script, never in a cell.
const XAGLE_URL = "https://yourcompany.xagle.io";
const XAGLE_TOKEN = "paste the Bearer token here";
/**
* =XAGLE_STAT("invoices", A2, B2, "aggregate=sum&status=paid")
* =XAGLE_STAT("new_clients", A2, B2, "client_type=lead")
* =XAGLE_STAT("item_sales", A2, B2, "aggregate=quantity&sku=WDG-100")
*
* from / to are sheet dates (or YYYY-MM-DD text). extra is an optional
* query string of aggregate and filters, exactly as in the API docs.
*/
function XAGLE_STAT(stat, from, to, extra) {
const day = d => (d instanceof Date)
? Utilities.formatDate(d, Session.getScriptTimeZone(), "yyyy-MM-dd")
: String(d);
let url = XAGLE_URL + "/api/v1/stats?stat=" + encodeURIComponent(stat)
+ "&from=" + day(from) + "&to=" + day(to);
if (extra) url += "&" + extra;
const response = UrlFetchApp.fetch(url, {
method: "get",
headers: { Authorization: "Bearer " + XAGLE_TOKEN, Accept: "application/json" },
muteHttpExceptions: true
});
const body = JSON.parse(response.getContentText());
if (body.errors) return Object.values(body.errors).flat().join(" ");
if (!body.success) return body.message;
return body.data;
}
Each cell makes one request, so a sheet with hundreds of stat cells makes hundreds of requests on every recalculation. Point the date cells at a fixed period rather than TODAY() where you can, and the API's rate limit will never be a concern.
Picking the right stat
| Question | Call |
|---|---|
| How many leads did we add? | new_clients with client_type=lead |
| How many prospects became customers? | converted_clients with converted_from=prospect&converted_to=customer |
| How many customers did we lose? | inactive_clients |
| What did we invoice? | invoices, aggregate=sum, status=all or status=sent depending on whether drafts belong in the figure |
| What is outstanding on invoices dated in the period? | invoices, aggregate=sum, measure=balance |
| What did we collect? | payments, aggregate=sum |
| What is the average invoice? | invoices, aggregate=avg |
| How many quotes did we win? | quotes with status=approved |
| What did we spend on a category? | expenses, aggregate=sum, category=... |
| How many of an item did we sell? | item_sales, aggregate=quantity, sku=... |