Skip to main content
Sales metric functions query the orders, orders_transactions, and orders_payout PostgreSQL tables, as well as Firestore collections, to return aggregated revenue and ticket data. All functions accept requests with a { "data": { ... } } body and return a { "message", "status", "data" } envelope.

total_sales

Returns total revenue grouped by date from the orders_transactions table. Accepts an optional event filter and date range.

Request parameters

data.event_id
string
Filter results to a specific event. If omitted, results span all events.
data.from
string
Start date in YYYY-MM-DD format. Matches records where date_created >= from.
data.to
string
End date in YYYY-MM-DD format. Matches records where date_created <= to.

Example request

{
  "data": {
    "event_id": "evt_9kXp2",
    "from": "2024-03-01",
    "to": "2024-03-31"
  }
}

Response

data.totales_date
array
One entry per calendar date with a sale.
data.totales
number
Grand total revenue across all dates in the result set.

Example response

{
  "message": "Total Ventas ",
  "status": 200,
  "data": {
    "totales_date": [
      { "date": "2024-03-15", "total": 1250.00 },
      { "date": "2024-03-16", "total": 875.50 }
    ],
    "totales": 2125.50
  }
}

total_sales_client

Returns total revenue grouped by date, filtered by client. Uses the same orders_transactions table as total_sales but filters on client_id instead of event_id.

Request parameters

data.client_id
string
Filter results to a specific client account. If omitted, all clients are included.
data.from
string
Start date in YYYY-MM-DD format.
data.to
string
End date in YYYY-MM-DD format.

Example request

{
  "data": {
    "client_id": "cl_7mNq4",
    "from": "2024-01-01",
    "to": "2024-06-30"
  }
}

Response

data.totales_date
array
One entry per calendar date with a sale for the given client.
data.totales
number
Grand total revenue for the client across the filtered period.

money_distribution

Returns revenue distributed across payment methods (custody accounts) for a given event and date range. Queries the orders_payout table, grouping by custody_account_id, custody_account_name, and amount_currency.

Request parameters

data.event_id
string
Filter to a specific event.
data.from
string
Start date in YYYY-MM-DD format.
data.to
string
End date in YYYY-MM-DD format.

Example request

{
  "data": {
    "event_id": "evt_9kXp2"
  }
}

Response

data.distribution
array
One entry per custody account (payment method) that received revenue.

Example response

{
  "message": "Datos Money Distribution ",
  "status": 200,
  "data": {
    "distribution": [
      {
        "custody_account_id": "ca_001",
        "custody_account_name": "Cash",
        "amount_currency": "USD",
        "amount": 3200.00
      },
      {
        "custody_account_id": "ca_002",
        "custody_account_name": "Stripe",
        "amount_currency": "USD",
        "amount": 1800.00
      }
    ]
  }
}

number_tickets_vs_sold

Compares the total number of allocated seats for an event against the number of tickets that have been sold. The seat allocation is read from Firestore (events/{event_id}/setup/zones), while sold ticket counts come from the orders PostgreSQL table.
This function requires a valid event_id — it reads the event’s zone setup document from Firestore directly. Omitting event_id will cause a runtime error.

Request parameters

data.event_id
string
required
The event to query. Used to look up seats_allocated from Firestore and filter the orders table.
data.from
string
Start date in YYYY-MM-DD format.
data.to
string
End date in YYYY-MM-DD format.

Example request

{
  "data": {
    "event_id": "evt_9kXp2"
  }
}

Response

data.sold
array
Always contains a single object with the sell-through summary.

Example response

{
  "message": "Datos cantidad de tickets vs tickets vendidos ",
  "status": 200,
  "data": {
    "sold": [
      {
        "seats_allocated": 500,
        "seats_sold": 312,
        "percentage_sold": 62.4
      }
    ]
  }
}

number_tickets_sold

Returns the raw count of sold tickets from the orders table. Unlike number_tickets_vs_sold, this function does not read from Firestore and does not require a valid event zone setup.

Request parameters

data.event_id
string
Filter to a specific event.
data.from
string
Start date in YYYY-MM-DD format.
data.to
string
End date in YYYY-MM-DD format.

Example request

{
  "data": {
    "event_id": "evt_9kXp2",
    "from": "2024-03-01",
    "to": "2024-03-31"
  }
}

Response

data.sold
array
Single-element array with the total sold count.

Example response

{
  "message": "Datos cantidad de tickets vendidos ",
  "status": 200,
  "data": {
    "sold": [
      { "seats_sold": 312 }
    ]
  }
}

general_platform_data

Returns platform-wide entity counts from Firestore. No filters are accepted — this function always returns totals across the entire platform.

Request parameters

This function takes no input parameters. Send an empty data object.
{ "data": {} }

Response

data.result
array
Single-element array with platform totals.

Example response

{
  "message": "Datos Generales de la plataforma ",
  "status": 200,
  "data": {
    "result": [
      {
        "total_events": 42,
        "total_offices": 18,
        "total_collaborators": 95,
        "total_clients": 12
      }
    ]
  }
}
general_platform_data reads four Firestore collections sequentially. For large deployments, response time scales with collection size.

types_of_collaborators

Breaks down the collaborator count by account type. The list of valid account types is read from data/collaborator_types in Firestore, then each type is counted by querying the u_collaborators collection.

Request parameters

This function takes no input parameters.
{ "data": {} }

Response

data.result
array
One entry per collaborator account type defined in data/collaborator_types.

Example response

{
  "message": "Cantidad de tipos de Colaboradores ",
  "status": 200,
  "data": {
    "result": [
      { "account_type": "Vendedor", "total_collaborators": 34 },
      { "account_type": "Supervisor", "total_collaborators": 8 },
      { "account_type": "Cajero", "total_collaborators": 53 }
    ]
  }
}
The set of account types returned is entirely driven by the data/collaborator_types Firestore document. Add or rename types there to change what this function reports.

Build docs developers (and LLMs) love