↓ Skip to main content
A pen and ink drawing of a workbench under a wooden wall rack. Brass stencil plates with different patterns of round and square holes hang on pegs, each with a teal tag, and one peg is empty with only its tag left. The missing stencil lies flat on a sheet of paper covered with small teal dots, and the dots under its holes show orange. A magnifying glass with a teal handle rests on the stencil and enlarges two orange dots.

Saved Queries and Search Terms in the Maximo REST API

The Maximo REST API in Practice - This article is part of a series.
Part 5: This Article
The earlier articles built a request by hand: the where clause, the select clause, sorting and paging and counts. Manage already holds many filters ready to use: the saved queries of the applications. This guide shows how a REST client finds them, runs them, and adds a search box on top.

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.

Why a saved query
#

A saved query keeps the filter in Manage, in one place:

  • The list matches the application. A mobile list or a report that runs ACTIVEANDNEWASSETS shows the same records as the query of that name in the application.
  • The filter can change without a new client. An administrator edits the clause in Manage, and every client gets the new list on its next request.
  • The clause can use the user’s data. A query can filter by the user’s default site or person, so one request gives each user their own list.

Find the queries: apimeta
#

GET /api/apimeta/<object structure> describes an object structure. Its queryCapability array lists every saved query the user may run on it:

GET /maximo/api/apimeta/mxapiasset
{
  "osName": "MXAPIASSET",
  "authApp": "…",
  "defaultPageSize": 100,
  "queryCapability": [
    {
      "name": "All",
      "title": "Select all",
      "ispublic": true,
      "href": "…/api/os/mxapiasset"
    },
    {
      "name": "ACTIVEANDNEWASSETS",
      "title": "Get list of ACTIVE and New Assets",
      "ispublic": true,
      "owner": "…",
      "default": false,
      "href": "…/api/os/mxapiasset?savedQuery=ACTIVEANDNEWASSETS"
    },
    {
      "name": "lookupAsset",
      "title": "lookup Asset",
      "hasParams": true,
      "javaMethod": true,
      "href": "…?savedQuery=lookupAsset&sqp:siteid={siteid}"
    }
  ]
}

The first entry is always All, the list without a filter. Each other entry carries:

PropertyWhat it means
namethe value for savedQuery, written exactly like this
titlethe description, good for a menu in your client
hrefthe ready request, with a placeholder for each parameter
ispublic, ownera public query, or a query of its owner only
hasParamsthe query takes parameters, passed as sqp:<name>
javaMethodthe query is a method in Java code, see below

The list depends on the user. It holds the public queries, the user’s own queries, and the queries of the application the object structure is bound to for security, the authApp. A public query can also be limited to the members of a role.

The kinds of saved queries
#

A name in the list can come from four places:

KindWhere it is definedName in the list
Application querya saved query of an application, for example AssetsACTIVEANDNEWASSETS, or RELENGINEER:LOWHEALTH for another application
Object structure querythe Query Definition action of the Object Structures applicationits own name
Query methoda method in Java code, part of Manage or of a customizationlookupAsset, with javaMethod: true
Script queryan automation script registered as a queryits own name

The queries of the application in authApp appear with their plain name. Queries of other applications carry the application in front, such as RELENGINEER:LOWHEALTH. Those appear when the object structure is set to load the queries of all applications.

Run a saved query: savedQuery
#

Pass the name in savedQuery:

savedQuery=ACTIVEANDNEWASSETS
oslc.select=assetnum,status,siteid
oslc.orderBy=+assetnum
oslc.pageSize=20

The rest of the request works as always. oslc.select, oslc.orderBy, paging, count=1 and group by all apply to the records the query returns.

Two details cost time when they go wrong:

  • The parameter name is case-sensitive. savedquery=ACTIVEANDNEWASSETS is ignored without a word, and the request returns every record. Write savedQuery with the capital Q.
  • The query name is case-sensitive too. savedQuery=activeandnewassets is refused with BMXAA8741E, “The activeandnewassets query name was not found”. Copy the name from apimeta.

A name with an application prefix contains a colon. Encode it as %3A in a URL you build by hand, as the href in apimeta does: savedQuery=RELENGINEER%3ALOWHEALTH.

The saved query and oslc.where
#

The saved query and oslc.where are joined with AND. The where clause narrows the saved query, and it can never widen it:

Every filter of a request narrows the same set of records Every filter of a request narrows the same set of records
Every filter of a request narrows the same set of records

On our test system, ACTIVEANDNEWASSETS returned only assets of the user’s default site, though its title says nothing about a site. With oslc.where=siteid="TEXAS" added, it returned no record at all. So check what a query really returns before you build on it. count=1 with and without the saved query shows it in two requests.

Parameters: sqp:
#

A query with hasParams: true takes its parameters as sqp:<name>. The href in apimeta names them in braces:

savedQuery=lookupAsset
sqp:siteid=BEDFORD
oslc.select=assetnum,siteid

A missing parameter makes the query fail. lookupAsset without sqp:siteid is refused with BMXAA9246E, “The query method could not be invoked”. The message points at the log, and the cause is only the missing parameter.

A KPI as the filter
#

savedQuery=kpi:<KPI name> takes the where clause of a KPI from the KPI Manager. Three rules:

  • The prefix is lower case. kpi: works. KPI: is read as the application KPI, and the request fails with BMXAA8741E, “query name was not found for KPI application”.
  • The KPI is missing from apimeta. You need its name from the KPI Manager.
  • Its where clause must fit the main object of the object structure. A clause written for work orders fails on MXAPIASSET.

An unknown KPI is refused with BMXAA9686E, “The KPI … is not found or its where clause field may be empty”.

A search box: oslc.searchTerms
#

oslc.searchTerms searches for text in a set of attributes, the way the search field of a list does. searchAttributes names the attributes:

oslc.where=siteid="BEDFORD"
searchAttributes=assetnum,description
oslc.searchTerms=pump
oslc.select=assetnum,description
{
  "member": [
    {
      "assetnum": "11430",
      "description": "Centrifugal Pump 100GPM/60FT HD"
    },
    {
      "assetnum": "11450",
      "description": "Centrifugal Pump 100GPM/60FTHD"
    }
  ]
}

A record matches when the text appears in one of the attributes, anywhere and in any case: PuMp finds the same records as pump.

Name the attributes in every request. Without searchAttributes, Manage takes the search attributes defined on the object structure. On our test system, MXAPIASSET, MXAPIWODETAIL, MXAPILOCATIONS and MXAPIPERSON had none, and every search was refused with BMXAA8763E, “There are no search attributes defined”. searchAttributes in the request settles it on any system. An unknown attribute there is refused with BMXAA9562E.

Several words
#

The text is split at the spaces, and a record matches when it contains any of the words:

oslc.searchTermsA record matches when
pumpone attribute contains “pump”
pump motorone attribute contains “pump”, or one contains “motor”
"centrifugal pump"the same as without quotes: “centrifugal” or “pump”
""centrifugal pump""the attribute contains both words

One pair of double quotes changes nothing. Two pairs keep the words together, and then a record needs all of them. On our test system the order of the words did not matter there: ""pump centrifugal"" found the same records as ""centrifugal pump"".

Two more results from our test system:

  • A search term with a slash, such as 100GPM/60FT, found nothing, though that text is in a description. Search for the parts, 100GPM.
  • A % in a search term found nothing. The search already matches anywhere in the text, so leave wildcards out.

oslc.searchTerm, singular, is ignored without an error, and the request returns every record. The parameter is oslc.searchTerms.

Search inside a saved query
#

Search terms work together with a saved query. This gives a search box over the user’s list:

savedQuery=ACTIVEANDNEWASSETS
searchAttributes=description
oslc.searchTerms=pump
oslc.pageSize=20

Query templates
#

A query template stores the rest of a request in Manage: the page size, the attributes to select and their order, and the search attributes. It is a record of the object structure MXAPIQUERYTEMPLATE, and querytemplate=<name> applies it. A template applies only to the object structure it was made for, and a template for another one is ignored without an error. Anything the request sets itself wins over the template. IBM’s saved query page shows how to create one.

Errors at a glance
#

RequestAnswerFix
savedquery=…, small q200, every recordwrite savedQuery
savedQuery= with a wrong name or case400 BMXAA8741Ecopy the name from apimeta
a query with hasParams, parameter missing400 BMXAA9246Eadd sqp:<name>=<value>
savedQuery=KPI:…400 BMXAA8741Ewrite kpi: in lower case
savedQuery=kpi: with an unknown KPI400 BMXAA9686Echeck the name in the KPI Manager
oslc.searchTerms without search attributes400 BMXAA8763Eadd searchAttributes
searchAttributes with an unknown name400 BMXAA9562Euse an attribute of the main object
oslc.searchTerm, singular200, every recordwrite oslc.searchTerms

Examples
#

Each request below returned data on our test system. Each line is one query parameter.

A saved query of another application, as a count:

savedQuery=RELENGINEER:MISSINGINSTALLDATE
oslc.where=siteid="BEDFORD"
count=1

A saved query, counted per status:

savedQuery=ACTIVEANDNEWASSETS
gbcols=status,count.*

A search over the work orders:

/api/os/mxapiwodetail
oslc.where=siteid="BEDFORD"
searchAttributes=description
oslc.searchTerms=pump
oslc.select=wonum,description,status
oslc.pageSize=20

All words must match:

oslc.where=siteid="BEDFORD"
searchAttributes=description
oslc.searchTerms=""centrifugal pump""
oslc.select=assetnum,description

What comes next
#

IBM’s own pages are the reference to keep next to this article:

The next article of the series covers domain values in a query. 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.

The Maximo REST API in Practice - This article is part of a series.
Part 5: This Article