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.

Configuring the Apply Query Parameter object

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

The layout builder window will open.

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 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.

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

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

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.

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

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.

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

This will open a new screen,

  1. 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.

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

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

  1. Right-click on the API Client object and select Properties from the context menu.

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

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.

  1. Click OK.

The parameters have been added.

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

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 a test flow.

Last updated

© Copyright 2023, Astera Software