Query With OQL

Object Query Language (OQL) is an Infor Nexus query language to retrieve objects from the Infor Nexus database. User-defined OQL statements are translated to native SQL statements on the server. The basic structure is similar to SQL, but it does not support all of the operations and functions that a normal SQL statement could.

You can run OQL on Infor Nexus native objects and your own custom objects. There is another whole section of documentation devoted to the use of OQL. For simplicity's sake, in this tutorial we will demonstrate the API call using a basic OQL instruction such as totals.totalQuantity>2999, which means "where the total quantity of the order exceeds 2,999 pieces/units."

HTTP Request

The request URL contains three new parameters: oql for specifying the OQL criteria, and the optional offset and limit parameters to perform record paging if desired.

Method GET
Base URL https://demo.infornexus.com/rest/{versionNumber}/{objectType}/query
Params oql={oql}  (optional)
offset={offset}   (optional)
limit={limit}   (optional)
Header x-nexus-api-key={datakey}
Authorization: {authorizationToken}
Accept: application/json

The values of the variables are as follows.

{versionNumber} Version number of the API, i.e., 3.1.
{objectType} The URL-encoded global type of an object to be returned from the query, which should be OrderDetail for this tutorial.
{datakey} The data key you obtained in the data key tutorial.
{oql} (optional)   The URL-encoded OQL expression, such as totals.totalQuantity>2999 for OrderDetail objects. If this parameter is omitted, the query will return all.
{offset} (optional)   An integer value that indicates how many records to skip in record paging. For example, if the value is 100, the current page starts from the 101th record. If this parameter is omitted, the page starts from the first record.
{limit}   (optional)   An integer value that indicates how many records to retrieve in record paging. For example, if the value is 10, the current page will retrieve 10 records. If this parameter is omitted, the page will retrieve from its starting position (after the offset, if specified) till the end of the record set.
{authorizationToken} The authorization token you obtained in the authentication tutorial, starting with the word Token.
HTTP Response

The response will return a list of objects that match the OQL criteria. If you are querying Infor Nexus native objects, only their summary fields will be returned, as these objects are large and returning all the fields would impact query and network performance. When you need more details than the summary fields, you can issue separate API calls to fetch individual objects as we did in the previous fetch-an-object tutorial.

On the other hand, if you are querying custom objects, all the fields will be returned, as the custom objects are reasonably small in general.

Body A list of objects that match the OQL criteria. The resultInfo field provides summary information such as total record count and record paging position (more explanation below). The result field returns an array of matched objects. Since we queried on a native object type OrderDetail, only the summary fields were returned. Note the sample response below indicated there are 19 matched records. For the sake of brevity, only the first order record is listed here.
{
    "__metadata": {
    "apiVersion": "3.1",
    "type": "OrderDetail",
    "self": "https://demo.infornexus.com/rest/3.1/OrderDetail/query?oql=totals.totalQuantity%3E2999"
  },
  "resultInfo": {
    "count": 19,
    "hasMore": false,
    "offset": 0,
    "firstRowNumber": 1,
    "estimatedTotalCount": 19
  },    
    "result": [
        {
            "__metadata": {
                "apiVersion": "3.1",
                "type": "OrderDetail",
                "uid": "1236435",
                "createTimestamp": "2001-02-21 21:20:16.171",
                "modifyTimestamp": "2001-02-21 22:12:24.265",
                "fingerprint": "0255ce12a793f4785a87791469fa8172",
                "self": "https://demo.infornexus.com/rest/3.1/OrderDetail/1236435",
                "redirectUrl": "https://demo.infornexus.com/en/trade/Contract?key=1236435"
            },
            "orderTerms": {
                "orderDate": {
                    "Issue": "2001-02-21",
                    "Latest": "2001-03-15"
                }
            },
            "orderFunctionCode": "Create",
            "poNumber": "test long description",
            "party": {
                "Buyer": [
                    {
                        "partyRoleCode": "Buyer",
                        "address": {
                            "countryCode": "US"
                        },
                        "name": "QA Tech Buyer",
                        "memberId": "5717989018004281",
                        "contact": {}
                    }
                ],
                "Seller": [
                    {
                        "partyRoleCode": "Seller",
                        "address": {
                            "countryCode": "US"
                        },
                        "name": "QA Tech Seller",
                        "memberId": "5717989018004282",
                        "contact": {}
                    }
                ]
            },
            "subMessageId": "1",
            "orderUid": "1236435",
            "totals": {}
        },

        /* Other orders omitted for brevity. */

    ]
}

Since the result array only contains the summary fields of the OrderDetail objects, if we need additional information about each order, we should loop through the array and retrieve the info in one of the following ways:

  1. Make a "fetch" API call based on result[i].__metadata.type and result[i].__metadata.uid as you did in the fetch-an-object tutorial.
  2. Make a "fetch" API call using the URL in result[i].__metadata.self. This is the same as method #1, but saves the work of composing the URL yourself.
  3. Navigate to the record in the Infor Nexus Platform in a web browser or WebView control, using the URL in result[i].__metadata.redirectUrl.
NOTE

The self field provides the URL that you can use for making an API call, while the redirectUrl field provides the URL for web browsing in the Infor Nexus Platform. Both can be quite useful, depending on the architecture of your application.

Record Paging

To ensure optimal network and application performance, an API-based OQL query supports server-side record paging by skipping the records you already received (using the optional offset parameter) and retrieving only the number of records you need (using the optional limit parameter). Here we provide a few scenarios of how the two parameters affect the returned result set. Suppose there is a total of 19 matched records as in the HTTP Response above and that we are displaying 10 records per page in our application.

Scenario Returned Results
offset omitted
limit omitted
All of the 19 records are returned. The resultInfo field is:
"resultInfo": {
    "count": 19,
    "hasMore": false,
    "firstRowNumber": 1,
    "estimatedTotalCount": 19
}
offset=0
limit=10
The first 10 records are returned (record #1 - 10). The resultInfo field is:
"resultInfo": {
    "count": 10,
    "hasMore": true,
    "firstRowNumber": 1,
    "estimatedTotalCount": 19
}
The count field indicates there are 10 records in this page, while estimatedTotalCount shows there are 19 records in total. The hasMore field is true, indicating there are more records after this page. The firstRowNumber shows the first row of this page is record #1.
offset=10
limit=10
The first 10 records are skipped, and the next 10 records are requested. But since there are only 9 records left, all of them are returned (record #11 - 19). The resultInfo field is:
"resultInfo": {
    "count": 9,
    "hasMore": false,
    "firstRowNumber": 11,
    "estimatedTotalCount": 19
}
The count field reflects there are only 9 records in this page, and hasMore is now false, indicating there are no more records after this page. The firstRowNumber shows the first row of this page is record #11.

Apart from performing record paging on the server side, another approach is to retrieve all the records in one go (by omitting the offset and limit parameters) and perform the desired paging effect on the client-side (i.e. in your own application). This is ideal when the result set is expected to be small and the paging effect is solely for the purpose of fitting data into a smaller viewing area or UI container. However, when dealing with potentially large result sets (such as purchase orders), it is recommended to utilize server-side paging to avoid unnecessary network load or application processing, so that your app will remain responsive and speedy.

cURL Syntax
curl -i "https://demo.infornexus.com/rest/{versionNumber}/{objectType}/query?oql={oqlClause}&offset={offset}&limit={limit}" -H "x-nexus-api-key: {datakey}" -H "Authorization: {authorizationToken}" -H "Accept: application/json"

Congratulations! You have now completed the entire Get Started Guide and are equipped with the basic knowledge to write your own apps for the Infor Nexus Platform. Feel free to click the menu items in the top navigation bar to read on more advanced subjects about AppXpress modules or API, or check out our code examples.