Skip to main content

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

OperationEndpoint
Get one figureGET /api/v1/stats (parameters in the query string) or POST /api/v1/stats (parameters as JSON)
List the available statsGET /api/v1/stats/catalog
Legacy pathGET 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:

ParameterRequiredMeaning
statyesWhich figure to calculate. One of the names in the catalog below.
fromyesFirst 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.
toyesLast day of the period, inclusive. Must not be before from.
aggregatenocount (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.

StatCounts / sumsAggregatesFiltersPermission
new_clientsClients 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.countclient_type (lead, prospect, customer, affiliate, trial, other, referral_partner, integration_partner, corporate)clients.view
converted_clientsClient type changes in the period, for example lead to prospect or prospect to customer.countconverted_to (required), converted_from (optional; any type when omitted)clients.view
inactive_clientsClients made inactive in the period (customers lost).countnoneclients.view
reactivated_clientsInactive clients made active again in the period.countnoneclients.view
invoicesInvoices by invoice date. Credit memos and refunds are not included. sum and avg use the invoice measure in base currency.count, sum, avgstatus (all, draft, sent, viewed, paid, unpaid, overdue, canceled, refunded, mailed, emailed; default all), measure (total, paid, balance; default total), client_id, invoice_tags, client_tagsinvoices.view
quotesQuotes by quote date. sum and avg use the quote total in base currency.count, sum, avgstatus (all, draft, sent, viewed, approved, rejected, canceled; default all), client_id, quote_tags, client_tagsquotes.view
recurring_invoicesRecurring invoice profiles created in the period. sum and avg use the profile total in base currency.count, sum, avgclient_idrecurring_invoices.view
paymentsPayments by the date received. Credit memo refunds are not payments and are left out. sum and avg are in base currency.count, sum, avgpayment_method (the method's name as shown in Xagle), client_idpayments.view
expensesRecorded expenses by expense date. Forecast rows are projections and are left out.count, sum, avgcategory (the category's name), vendor_id, client_idexpenses.view
item_salesInvoice 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, sumitem_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.

Tags: invoice_tags, quote_tags and client_tags take one tag name or several separated by commas, and match any of them. client_tags filters by the tags on the document's client. A name that matches no tag in your company returns 0, never an unfiltered total.

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

QuestionCall
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=...