Reports

Run Query

POST https://{organisation}.clearlrs.com/api/reports/query

Runs an ad-hoc report query against the data stored in the system. The structure of this query is very flexible with the ability to target different data sources, filter and aggregate the data in numerous ways. The following documentation is not comprehensive but covers most major options.

Query Parameters

Request Body

[
	{
		"name": "User 1",
		"completed": true
	},
	{
		"name": "User 2",
		"completed": false
	}
]

Due to the powerful nature of this endpoint, it is possible to run queries across huge amounts of data which result in a very slow query. As such, it is recommended that filters are used to efficiently restrict the amount of data being queried.

Request Body

dataSource

The following table outlines available data sources in Clear LRS. See the Data Sources section below for a list of available metrics for each data source.

values

An Array of Objects composed of the following fields:

filters

A recursive object that can be used to build complex filter conditions to restrict the data retrieved when generating a report. The structure of a the filter object is of a single key indicating the type of comparison to be performed, and an Array of operations to perform the comparison against.

  • and – All operations in the Array must be met for the filter to match.

  • or – Any operation in the Array must be met for the filter to match.

  • = – The metric must match any of the values in the Array.

  • != – The metric must not match any of the values in the Array.

  • < – The metric must be less than the second value in the Array.

  • <= – The metric must be less than or equal to the second value in the Array.

  • > – The metric must be greater than the second value in the Array.

  • >= – The metric must be great or equal to the second value in the Array.

  • >< – The metric must be between the first and second values in the Array (non-inclusive).

  • <> – The metric must be less than the first value in the Array and greater than the second value in the Array (inclusive).

  • exists – A value for the metric must exist.

  • !exists – A value for the metric must not exist.

Example Filters Object
filters: {
	and: [
		{ "=": [ { type: "metric", key: "device" }, "mobile", "desktop" ] },
		{ or: [
			{ "!=": [ { type: "attribute", key: "State" }, "VIC" ] },
			{ "exists": [ { type: "attribute", key: "Country" } ] }
		] }
	]
}

In the above example, the filter would retrieve all records where:

  • The device metric is equal to either mobile or desktop, AND;

    • The user's State attribute is not equal to VIC, OR;

    • A value for the user's Country exists

group

An Array of Objects composed of the following fields:

Accumulator Types

When grouping on a field, it's necessary to specify an accumulator for all other values so the aggregator knows how to aggregate them together. The following are all available accumulators:

  • first – Picks the first value in the result set. Should be used with a sort stage.

  • last – Picks the last value in the result set. Should be used with a sort stage.

  • min – Picks the greatest of all values in the result set.

  • max – Picks the least of all values in the result set.

  • sum – Calculates the total of all values in the result set.

  • avg – Calculates the average of all values in the result set.

Example Group Array
group: [ {
	fields: [
		{ type: "metric", key: "activity" },
		{ type: "attribute", key: "State" }
	],
	values: {
		completion: "sum"
	}
} ]

In the above example, the group stage will calculate the sum of all completions in the system, split by activity and State.

sort

An Array of Objects composed of the following fields:

Data Sources

status

Stability: Stable The metrics in this data source are unlikely to change and maintaining compatibility is a priority.

completions

Stability: Under Migration This is a legacy data source that is currently being migrated to a cleaner structure. Keys, Key Paths and the formats of some values are highly likely to change.

analytics

Stability: Stable The metrics documented here are unlikely to change and maintaining compatibility is a priority. However, additional undocumented metrics may exist in this data source that are prone to change.

Last updated