====Example Queries====
Below are some example [[graphql:start|GraphQL]] queries that retrieve ARDI data.
===Query by ID Number===
The following query gets the ID number and name of the ARDI asset with the ID '44'.
query {
asset(id: 44) {
id
name
}
}
[[https://demo.optrix.com.au/s/pl/graphql?query=query%20MyQuery%20{%20asset(id:%2048)%20{%20id%20name%20}%20}|Open a Sample - Gets Item By ID]]
===Query by Name/ERN/Code===
The following query gets the ID number and name of the ARDI asset with the name, equipment reference number or code 'AR925'.
query {
asset(name: "AR925") {
id
name
}
}
[[https://demo.optrix.com.au/s/pl/graphql?https://demo.optrix.com.au/s/pl/graphql?query=query%20MyQuery%20{%20asset(name:%20%22Paint%20Line%22)%20{%20id%20name%20speedActual%20}%20}|Open a Sample - Gets Item By Name]]
===Query by Type===
The following query gets a list of all **pumps** in the system.
query {
pump {
id
name
}
}
[[https://demo.optrix.com.au/s/pl/graphql?https://demo.optrix.com.au/s/pl/graphql?query=query%20MyQuery%20{%20bridleRoller%20{%20id%20name%20speedActual%20}%20}|Open a Sample - Gets All Bridle Rollers]]
===Query Base Assets===
If you want to query the **base of a hierarchy** or the origin points/source of relationships, you can use the relationship name.
query {
power {
name
id
}
}
//This creates a list of the items that are a source of electrical power.//
[[https://demo.optrix.com.au/s/pl/graphql?https://demo.optrix.com.au/s/pl/graphql?query=query%20MyQuery%20{%20location%20{%20id%20name%20}%20}|Open a Sample - Location Hierarchy Base]]
===Get a List of Available Properties===
To get a list of the properties available on an asset (or assets), use the **properties** value.
query {
asset(name: "AR925") {
id
name
properties
}
}
===Get a List of Directly Connected Items===
To get a list of the items //inside// an item (meaning assets under the given asset via the //Location// relationship), you can use the following...
query {
asset(name: "AR925") {
id
name
inside {
id
name
temperature
}
}
}
//Note that you can have a different set of attributes on the item **inside**//.
===Get a List of All Connected Items===
To get a list **all** of the items down or upstream from an asset (in this example, the //power// relationship) you can use the following...
query {
asset(name: "AR925") {
id
name
allPoweredBy {
id
name
temperature
}
}
}
//In this case **poweredBy** lists the directly connected assets, and **allPoweredBy** lists all of the indirectly connected assets.//.
===Get a Nested List of All Connected Items===
The above query runs very quickly, but while the results include every down-stream item, the //details// of the connections between them are lost.
If you're trying to keep some information explaining how the various parts are connected, you can use a trick we've added.
If you ask for related items but do **not include any query details** (for example, you don't name the individual columns you want returned), it will //use the details of the parent query again//. This lets you make a 'loop' that will run through your relationships and hierarchies.
query {
asset(name: "AR925") {
id
name
poweredBy
}
}
===Requesting History===
If you want to get history of the values you're asking for, you can use **from**, **to** and **samples** parameters. Note that the times given are in YYYY-MM-DD HH:MM:SS format and in UTC time.
query {
asset(name: "AR925", from: "2025-10-10 10:00:00", to: "2025-10-11 10:00:00", samples: 1000) {
id
name
temperature
}
}
//The above example will load roughly 1000 samples of data on the temperature of asset AR925//
===Requesting Relative History===
If you want to get history but want it to be //relative to the current time// (for example, the last 24 hours) you can use the **range** and **samples** parameters.
query {
asset(name: "AR925", range: "24 hours", samples: 100) {
id
name
temperature
}
}
//The above example will load roughly 100 samples of data covering the previous 24 hours.//
===Requesting Events===
Events can be accessed using the //name of their source//. For example, if you have downtime records available from an event source named **downtimes**, that's also the name of the object in GraphQL.
query {
downtimes(range="48 hours")
{
name
start
end
properties
}
}
//The above example will load events from the 'downtimes' event source for the last 48 hours.//