oslc.select shapes them, and
sorting and paging walks through them. Often you only need a
number: how many, how much, which values exist. The REST API can answer that in one request and
leave the records in the database.The rules here come from IBM’s documentation and from our own work with the REST API, on Manage in
the MAS 9.2 series. We ran every request on our test system, against IBM’s demo data, as a user
without administrator rights. The examples read the object structure MXAPIASSET at the site
BEDFORD, and the work orders through MXAPIWODETAIL.
There are four forms, and each one answers a different question:
How many records: count=1#
count=1 returns the number of records that match the where clause, and nothing else:
oslc.where=siteid="BEDFORD" and status="OPERATING"
count=1{ "totalCount": 199 }The database counts the rows. No record is read, so this is the cheapest request in the API. It fits a dashboard tile, a check before an export, or a test that a filter works.
The total with every page#
When you read records page by page and also want the total, add collectioncount=1.
responseInfo then carries totalCount and totalPages:
"responseInfo": {
"totalCount": "…",
"totalPages": "…",
"pagenum": 1,
"nextPage": { "href": "…" }
}An administrator can switch the totals on for every request with the system property
mxe.oslc.collectioncount. On our test system it was on, so the totals came without the
parameter. Send collectioncount=1 anyway when your client needs the total, and the request works
on every system.
A number for each record#
An aggregate in oslc.select computes a number over a relationship of each record. Asking for
the open work orders of an asset, and their priorities:
oslc.where=siteid="BEDFORD" and assetnum="11430"
oslc.select=assetnum,openwo._dbcount,openwo.wopriority._dbmax{
"assetnum": "11430",
"openwo": {
"_dbcount": 43,
"wopriority": { "_dbmax": 8 }
}
}The database computes the values. The work orders themselves never reach the answer. Six functions exist:
| Term | Returns |
|---|---|
<rel>._dbcount | the number of related records |
<rel>._exists | true or false: does the relationship have a record |
<rel>.<attr>._dbsum | the sum of the attribute |
<rel>.<attr>._dbavg | the average of the attribute, see below |
<rel>.<attr>._dbmax | the largest value |
<rel>.<attr>._dbmin | the smallest value |
A few rules decide whether the request works:
- The result is nested. Each relationship becomes an object, and each attribute an object inside it, as in the JSON above.
- An alias makes it flat.
openwo._dbcount--wocountreturns"wocount": 43at the top level of the record. For a client this is the easier form to read. - Sum, average, maximum and minimum need a number.
openwo.wonum._dbmaxis refused with BMXAA8882E, becausewonumis a text attribute. - One relationship deep for the attribute functions.
location.locoper._dbcountcounts across two relationships.location.locoper.locpriority._dbsumis refused withoslc#invaliddbstat.
In a list, every record gets its own numbers. This returns each asset with the count of its open work orders:
oslc.where=siteid="BEDFORD"
oslc.select=assetnum,description,openwo._dbcount--wocount
oslc.orderBy=+assetnum
oslc.pageSize=20The average counts the records without a value#
_dbavg is the sum divided by the count of all related records, and that count includes the
records where the attribute is empty. We measured it on an asset whose open work orders include
task rows without a priority: _dbavg equalled _dbsum divided by _dbcount, empty rows included.
An example with three work orders makes the difference clear:
| Work order | Priority |
|---|---|
| 1 | 2 |
| 2 | 4 |
| 3 | empty |
_dbavg returns 2: the sum 6 divided by three records. The average most people expect is 3, the
sum divided by the two records that have a priority. The group by average in the section below
returns 3. When empty values are common, compute the average yourself from _dbsum and a count of
the records that have a value.
Aggregates in the where clause#
The same terms filter records. This returns the assets with more than three open work orders:
oslc.where=siteid="BEDFORD" and openwo._dbcount>3
oslc.select=assetnum,openwo._dbcount--wocount_dbsum, _dbavg, _dbmax and _dbmin work the same way, for example
openwo.wopriority._dbmax>=3. To test whether a relationship has records, the where clause uses
_dbexists:
oslc.where=siteid="BEDFORD" and openwo._dbexists=0
count=1This counts the assets without an open work order. Note the two names: _dbexists in the where
clause, _exists in the select clause. openwo._dbexists in oslc.select is refused with
BMXAA4176E, “Attribute _DBEXISTS does not exist”. The
where clause article has more on filtering by a relationship.
Which values exist: distinct#
distinct takes the place of oslc.select and returns the values of one attribute, each value
once:
oslc.where=siteid="BEDFORD"
distinct=status["ACTIVE", "DECOMMISSIONED", "NOT READY", "OPERATING"]The answer is a plain JSON array, without member and without responseInfo. Three details:
- An empty value is part of the list.
distinct=serialnumreturnsnullas one of the values. A client that fills a filter list from it has to skip or label that entry. oslc.selectandoslc.pageSizeare ignored. The array holds every value in one answer.- Name one attribute.
distinct=status,priorityreturns a status for each distinct pair of status and priority, so the list repeats the same status several times. For combinations, use group by.
An unknown attribute is refused with BMXAA10000E, “Invalid attribute nosuchattr specified for distinct clause”.
Numbers per group: gbcols#
Group by returns one row per group, with the aggregates you ask for. gbcols names the grouping
attributes and the functions:
oslc.where=siteid="BEDFORD"
gbcols=status,count.*[
{
"status": "ACTIVE",
"status_description": "Active",
"count": 40,
"collectionref": "…"
},
{ "status": "DECOMMISSIONED", "…": "…" }
]oslc.where filters the records before they are grouped, and a saved query works too. The
answer is a JSON array, one entry per group. An attribute with a domain also gets its
description, as status_description above.
The functions are written as <function>.<attribute>, and the result is named
<function>_<attribute>:
In gbcols | In the answer |
|---|---|
count.* | count, the number of records in the group |
count.priority | count_priority, the records with a priority |
sum.priority | sum_priority |
avg.priority | avg_priority, the average of the records with a value |
max.priority, min.priority | max_priority, min_priority |
A group whose records all have an empty value gets null for the function. Several grouping
attributes give one row per combination: gbcols=siteid,status,count.* counts the assets per site
and status. A list of only functions, such as gbcols=count.*,max.priority, gives one row with
the totals over all matching records.
Sorting the groups#
gbsortby sorts the rows, with the same sign rules as
oslc.orderBy:
gbcols=siteid,count.*
gbsortby=-count.*This lists the sites with the most assets first. The + must be encoded as %2B here too. A raw
+ is refused with BMXAA9757E, a general message that names no cause.
The link of a group#
Each row carries a collectionref that should lead to the records of the group. On our test
system that link carried two question marks, …/mxapiasset?&lean=1?oslc.where=…, and following
it did not return the records of the group. Build the link from the row instead: the request’s own where clause, plus
the group’s values.
oslc.where=siteid="BEDFORD" and status="ACTIVE"Ranges: gbrange#
gbrange merges values into ranges, and counts each range. A list of values goes in square
brackets with a colon:
oslc.where=siteid="BEDFORD"
gbcols=status,count.*
gbrange=status={[OPERATING:NOT READY]}OPERATING and NOT READY become one row, with "status": ["OPERATING", "NOT READY"] and their
summed count. The other values stay rows of their own. Number ranges use .., with [ and ]
for an included bound and ( and ) for an excluded one:
gbcols=priority,count.*
gbrange=priority={[1..3],[4..7)}This returns one row for priority 1 to 3, one for 4 to 6, and the values outside the ranges, such
as an empty priority, as rows of their own. A range needs count.* in gbcols. Without it, the
request is refused with BMXAA9757E.
Which form for which job#
| Job | Form |
|---|---|
| A dashboard tile with one number | count=1 |
| The total next to a paged list | collectioncount=1 |
| A column with the open work orders per asset | oslc.select with openwo._dbcount--wocount |
| Only the assets with open work orders | oslc.where with openwo._dbexists=1 |
| The values for a filter list | distinct |
| A chart: records per status, per site | gbcols with count.* |
| A chart with buckets, such as priority bands | gbcols with gbrange |
Errors at a glance#
| Request | Answer | Fix |
|---|---|---|
openwo.wonum._dbmax | 400 BMXAA8882E | use a numeric attribute |
location.locoper.locpriority._dbsum | 400 oslc#invaliddbstat | one relationship deep |
openwo._dbexists in oslc.select | 400 BMXAA4176E | use openwo._exists |
distinct=nosuchattr | 400 BMXAA10000E | use an attribute of the main object |
gbcols= empty | 400 BMXAA9307E | name at least one column |
gbcols=nosuchattr,count.* | 400 BMXAA9757E | check every name in gbcols |
gbsortby with a raw + | 400 BMXAA9757E | encode it as %2B |
gbrange without count.* | 400 BMXAA9757E | add count.* to gbcols |
BMXAA9757E says only “Error executing the request”. It stands for several causes, so check the group by parameters one by one.
Examples#
Each request below returned data on our test system. Each line is one query parameter.
Assets with open work orders, and how many each has:
oslc.where=siteid="BEDFORD" and openwo._dbexists=1
oslc.select=assetnum,openwo._dbcount--wocount
oslc.orderBy=+assetnum
oslc.pageSize=20The planned hours of the work orders per status:
/api/os/mxapiwodetail
oslc.where=siteid="BEDFORD"
gbcols=status,count.*,sum.estdur
gbsortby=-count.*The statuses in use at a site, for a filter list:
oslc.where=siteid="BEDFORD"
distinct=statusAssets per priority band:
oslc.where=siteid="BEDFORD"
gbcols=priority,count.*
gbrange=priority={[1..3],[4..7)}What comes next#
IBM’s own pages are the reference to keep next to this article:
- Selecting in the IBM Maximo Manage documentation, with the aggregation functions.
- Selecting distinct data in the same documentation.
- Aggregation in IBM’s Maximo REST API guide on GitHub, the only IBM page on group by.
The next article of the series covers saved queries. The series overview lists all parts. If you want help with the REST API in your own Manage, our services page shows how we work, or get in touch.
IBM and Maximo are trademarks of International Business Machines Corporation, registered in many jurisdictions worldwide.
