Event sorting
- Last UpdatedOct 03, 2025
- 2 minute read
Events returned can be sorted based on one filter used within the where field by using the orderBy field within the events on a query.
Note: The values within the orderBy field must match a valid filter within the where field.
Valid filters include: standard event fields, properties, and properties on components. Sorting on relationships is not supported.
Note: If you are sorting on a string using an endsWith filter, the returned results will be sorted in reverse alphabetical order.
Ends with example
If you have two events:
{
"id": "Event1",
"name": "FirstEvent"
}
{
"id": "Event2",
"name": "SecondEvent"
}
And you filter on name in DESC order. The returned results would be:
{
"data": {
"events": {
"items": [
{
"id": "Event1",
"name": "FirstEvent"
},
{
"id": "Event2",
"name": "SecondEvent"
}
]
}
}
}
Explanation
The expected result might be Event2 followed by Event1 since alphabetically the F in FirstEvent comes before the S in SecondEvent. But since the sorting for specifically endWith string filters goes in reverse order it is actually being sorting alphabetically based on the t* at the end of first and the d at the end of second.
OrderBy structure
The orderBy field requires information on the filter being used and a direction by which to sort.
Direction input
Valid directions are:
-
ASC = Ascending
-
DESC = Descending
Sorting by standard event fields
To sort on a standard event field such as name, duration, and createdDate, you must only provide the relevant field within the filter information section of orderBy.
Event name
To sort on event name you would only provide the field name and the desired direction within the orderBy field.
Event name request
Sort events based on name that starts with "E" in descending order.
where: {
name: { startsWith: "E" }
}
orderBy: {
name: {
direction: DESC
}
}
Event name response
{
"data": {
"events": {
"items": [
{
"id": "ExampleEvent2",
"name": "Event2"
},
{
"id": "ExampleEvent1",
"name": "Event1"
}
]
}
}
}
Sorting by event level properties
To sort events based on properties, you must provide properties, property id, and direction fields within the orderBy field.
Note: In the case where there are multiple filters that match the provided property id, the first one stated in the where field will be used to sort by.
Event level properties request
Sort events based on a property id that equals "Flow Rate" and a numberValue that is greater than 1 in descending order.
where: {
properties: [{ id: "Flow Rate", numberValue: { gt: 1} }]
}
orderBy: {
properties: {
id: "Flow Rate",
direction: DESC
}
}
Event level properties response
{
"data": {
"events": {
"items": [
{
"id": "ExampleEvent1",
"name": "Event1",
"properties": [
{
"id": "Flow Rate",
"numberValue": 3
}
]
},
{
"id": "ExampleEvent2",
"name": "Event2",
"properties": [
{
"id": "Flow Rate",
"numberValue": 2
}
]
}
]
}
}
}