Configuring Sorting and Filtering in API Flows

The Apply Query Parameter object is used to filter and sort data in an API flow in accordance with the user application. Its location in an API flow can depend on when sorting or filtering is required in the processing of the API request.

Gif

Configuring the Apply Query Parameter object

1. To start, right-click on the object and select Properties from the context menu.

02-Apply-auery-properties-click

The layout builder window will open.

03-Layout-Builder

This is where the layout of the incoming data is going to be mapped. It can be automatically mapped from a preceding object.

Note: The left-side window shows the node hierarchy of the Apply Query Parameter object.

For our use case, we have a flow that fetches order items from the database for the given OrderID in the request. Now, to allow sorting and filter operations on this response data, we will add the Apply Query Parameter object right after the Database Lookup object and before the REST Response object.

The position of this object in a flow can depend on where it is required. It can be placed anywhere between objects in the API flow.

Filter-Gif.mp4

Thus, our layout builder is populated according to our flow.

41-Apply-Query-Layout

2. Once done, click Next. Here, you can enable filter and sort functions on the API response data.

43-Apply-Query-Checkboxes

Apply Filter Parameters: This allows users to send filter parameters of response layout fields in the request URL.

Apply Sort Parameters: This allows users to send sort_by parameter of response layout fields in the request URL.

3. Select Ok after you are done with this window and the configuration will be completed.

42-Flow-Configured

The Apply Query Parameter object has been configured to return responses as per the sort or filter parameters requested.

Applying Filter and Sort Parameters in Request

1. To further examine filter and sort functionalities, deploy the flow you have used the Apply Query Parameter object in.

46-Deploying-Flow

2. To deploy the API flow, select the third option from the right, on the designer toolbar

47-Deploy-Click

This will open a new screen,

3. Provide the Deployment Name and the Config File Path, if any, and click Ok.

Generate Test Flow for API: Selecting this option will generate a flow to execute a test request for the API in run-time, to use after deployment.

48-Deployment-Popup

4. Once done, you can open the generated test flow from the job progress window.

01-Job-Progress

Note: Since the test flow was generated during the deployment, it already has a REST Connection, and REST Client auto-populated with the request configuration.

49-Test-flow-REST

5. Right-click on the REST Client object and select Properties from the context menu.

50-Open-Rest-Client-Parameters

6. Click Next and you will be led to the Parameters screen.

51-Sort-by-and-filter

Here, you can use the sort_by parameter or the filter parameters, with the appropriate syntax, to obtain accurate data.

To sort the response data, we can define the query parameter ‘sort_by’. This parameter takes comma-separated values for multiple fields that need to be sorted. The syntax for each sort is as follows:

FieldName - SortOrder - Where the sort order can either be asc for ascending or desc for descending.

For example, a sort value as UnitPrice-asc, ProductName-desc would first sort the data by Unit Price in ascending order, then apply a second sort by Product Name in descending order.

FieldName [Operator] - To add a filter on any of the response fields, you can define a query parameter with this syntax. The supported operators include,

  • Equals to – eq

  • Not equal to – neq

  • Greater than – gt

  • Greater than or equals to – gte

  • Less than – lt

  • Less than or equals to - lte

For example, to apply a filter on discount, we have defined a query parameter Discount[gt] as the parameter key and 5 as the value for this filter, implying to only show discount records greater than 5 in the response data. Additionally, more such filter parameters can also be added for other response fields.

Note: This parameter name is defined as a Parameter Key because the name consists of special characters [] which are not allowed in the Name column. Parameter Key is used instead of Name in the actual API request.

7. Click Ok.

52-configured-REST-Client

The parameters have been added.

8. Next, right-click on the REST Client object and select Preview Output to make an API call with the defined parameters.

53-Successful-Run

The status code ‘200’ shows that the API call was made successfully.

This concludes the usage of the Apply Query Parameter object after deployment, within an test flow.