Report Run API

Execute a SQL-based report (by slug) and return its result set.

Endpoint

GET/report/run

Runs a report identified by its slug and returns the rows produced by its SQL template. Filtering and date placeholders are applied automatically when present in the SQL.

Authentication

Provide your API token in the request headers:

X-Api-Token: your_token_prefix.your_token_secret

Parameters

Identification

Parameter Type Required Description
report string Required Report slug (filename without .sql), e.g. flight_bookings_summary

Common Filters

Filters are applied only if the SQL contains the relevant placeholders (e.g. {{{FILTER}}}). Unsupported filters are safely ignored.

Parameter Type Applied Condition Description
branchIDintegerAND b.ID = :branchIDBranch filter
consultantIDintegerAND co.ID = :consultantIDConsultant filter
clientIDintegerAND cli.ID = :clientIDClient filter
tripIDintegerAND t.ID = :tripIDTrip filter
supplierIDintegerAND s.ID = :supplierIDSupplier filter
productIDintegerAND p.ID = :productIDProduct filter
tripStatusstringAND t.tripStatus = :tripStatusTrip status
sourcestringAND t.source = :sourceBooking source
isActiveboolean/intAND ts.isActive = :isActiveActive sectors only
minTotalintegerAND ts.total >= :minTotalMinimum sector total (in cents)
maxTotalintegerAND ts.total <= :maxTotalMaximum sector total (in cents)

Date Filters

When present in the SQL, date placeholders are replaced automatically using the following query parameters.

Parameter Type Applies To Placeholder
startDatedateGeneral date rangeMultiple (e.g. {{{DATE_SECTOR_TRAVEL_DATE}}}, {{{DATE_TRIP_OPENED}}})
endDatedateGeneral date rangeMultiple
travelStartDatedateTravel date range{{{TRAVEL_DATE}}}
travelEndDatedateTravel date range{{{TRAVEL_DATE}}}
Tip: Use ISO dates (YYYY-MM-DD). If only one bound is provided, the other defaults to a very early/late sentinel.

Usage Examples

Run by slug with date range and branch
GET /report/run?report=flight_bookings_summary&startDate=2024-01-01&endDate=2024-12-31&branchID=3
Run with consultant filter
GET /report/run?report=flight_bookings_summary&consultantID=27
Run with travel-date window
GET /report/run?report=flight_bookings_summary&travelStartDate=2024-02-01&travelEndDate=2024-02-28

Response Format

{
  "success": true,
  "data": {
    "report_name": "flight_bookings_summary",
    "display_name": "Flight Bookings Summary",
    "filters_applied": {
      "startDate": "2024-01-01",
      "endDate": "2024-12-31",
      "branchID": 3
    },
    "row_count": 150,
    "execution_time": 245.67,
    "headers": ["Trip","Sector_ID","Branch","Depart","Carrier","Reloc","Travel","Return","Dest","Gross","Net","Markup","Discount","Comm","Client","Phone","Email","DoB"],
    "rows": [
      { "Trip": 12345, "Sector_ID": 67890, "Branch": "MEL", "Depart": "MEL", "Carrier": "QF", "Reloc": "MEL", "Travel": "2024-02-01", "Return": "2024-02-05", "Dest": "SYD", "Gross": "450.00", "Net": "400.00", "Markup": "25.00", "Discount": "0.00", "Comm": "35.00", "Client": "John Smith", "Phone": "+61400123456", "Email": "john@example.com", "DoB": "1985-06-15" }
    ]
  },
  "timestamp": "2025-08-22T00:00:00+00:00"
}

Error Responses

Missing report slug
{
  "success": false,
  "error": "Missing required parameter: report",
  "code": 400
}
Report not found on server
{
  "success": false,
  "error": "Report execution failed",
  "code": 500,
  "details": {
    "report": "unknown_slug",
    "error": "Report SQL file not found: unknown_slug"
  }
}

Code Examples

JavaScript (Fetch)

const response = await fetch('/report/run?report=flight_bookings_summary&perPage=10', {
  headers: { 'X-Api-Token': 'your_token_prefix.your_token_secret' }
});
const data = await response.json();
if (data.success) {
  console.log(data.data.headers);
  data.data.rows.forEach(r => console.log(r));
}

PHP (cURL)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, '/report/run?report=flight_bookings_summary&startDate=2024-01-01&endDate=2024-12-31');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['X-Api-Token: your_token_prefix.your_token_secret']);
$response = curl_exec($ch);
$data = json_decode($response, true);
curl_close($ch);
if ($data['success']) {
    foreach ($data['data']['rows'] as $row) {
        print_r($row);
    }
}

Python (requests)

import requests
headers = {'X-Api-Token': 'your_token_prefix.your_token_secret'}
resp = requests.get('/report/run', params={
    'report': 'flight_bookings_summary',
    'startDate': '2024-01-01',
    'endDate': '2024-12-31'
}, headers=headers)
data = resp.json()
if data['success']:
    for row in data['data']['rows']:
        print(row)

Notes

  • Use the /report/list endpoint to discover available report slugs.
  • Amounts returned by SQL may already be formatted (e.g., FORMAT(x/100, 2)) depending on your SQL template.
  • Unknown filters or missing placeholders are ignored without error.
  • Date parameters must use the exact names shown (e.g., startDate, travelStartDate).