Filtering and sorting data

Data filtering is based on field conditions. The Filter object allows you to create complex conditions using logical operations and grouping conditions as needed.

Restriction: Filtering by text search is not available for Query API.

Filter data using complex filters:

  • Filter by date range.

  • Filter by segment.

  • Filter by field and unit field value.

{filterIds:[String], <logical_operator|comparison_operator>:Filter|String}

Where the logical operators are:

  • {and:[Filter]}

  • {or:[Filter]}

  • {not:[Filter]}

  • isNull:true|false

and: [ {filter1}, {filter2} ] , or:[ {filter1}, {filter2} ]

And the comparison operators are:

  • {in:[String]}

  • {<gte|gt|lt|lte>:[String]}

Example: Filter specific survey IDs

{and:[
    {fieldIds: ["5495387","5495381"]}
]}

Example: Filter data ranges

{and:[ 
    {fieldIds: ["data_field"], "gte": "1" }, 
    {fieldIds: ["data_field"], "lte": "10" } 
 ]}

Example: Filtering date ranges

{"and":[ 
    {fieldIds: ["e_responsedate"], "gte": "2016-02-01"}, 
    {fieldIds: ["e_responsedate"], "lte": "2018-02-01"} 
 ]}

Example: Filtering enumerated fields

{and:[
    {fieldIds: ["enumerated_field"], "in": ["1","2","3","4"]}
]}

Example: Filtering segments

{and:[
    {fieldIds: "q_global_nps_0to10", in: ["0", "1", "2", "3"]}
]}

Example: Filtering comments

{and:[
    {fieldIds: "comment_length_q_global_nps_comment_txt", gt: "0"}
]}

Example: Combining filters

filter: {
      or: [
        {
          and: [
            { fieldIds: "e_responsedate", gte: "2020-01-01" }
            { fieldIds: "comment_length_q_global_nps_comment_txt", gt: "0" }
            { fieldIds: "q_global_nps_0to10", in: ["0", "1", "2", "3"] }
          ]
        }
        { fieldIds: "e_responsedate", lt: "2020-01-01" }
      ]
    }

Sorting

Query API can return lists of records that are ordered (sorted) by specific fields. The orderBy argument allows you to sort results from your query in ascending or descending order by specifying the ASC or DESC direction in the orderBy input object.

Example: showing most recent records

query getFeedbackData {
  feedback(
    filter: { fieldIds: "e_responsedate", gte: "2020-01-01" }
    orderBy: { fieldId: "e_responsedate", direction: DESC }

Supported fields for filtering and sorting

The best practice to find fields that can be used for filtering and sorting in the Query API is using the the fields node. The schema has a filterable node which says which fields are filterable, and also features an argument to only fetch filterable fields.

Example

query filterableFields {
        fields(
            filterable: true,
            first: 5,
            after: null
        ) {
            totalCount
            pageInfo {
                endCursor
                hasNextPage
            }
            nodes {
                id
                dataType
                filterable
            }
        }
    }

Example response

{
  "data": {
    "fields": {
      "totalCount": 2620,
      "pageInfo": {
        "endCursor": "NQ==",
        "hasNextPage": true
      },
      "nodes": [
        {
          "id": "a_action_plan_attachments_yn",
          "dataType": "ENUM",
          "filterable": true
        },
        {
          "id": "a_action_plan_completion_date",
          "dataType": "DATETIME",
          "filterable": true
        },
        {
          "id": "a_action_plan_creation_date",
          "dataType": "DATETIME",
          "filterable": true
        },
        {
          "id": "a_action_plan_creator",
          "dataType": "INT",
          "filterable": true
        },
        {
          "id": "a_action_plan_creator_name",
          "dataType": "STRING",
          "filterable": true
        }
      ]
    }
  },
  "errors": null,
  "_links": null,
  "_allowed": [
    "POST",
    "GET"
  ]
}

Alternative sets

Some fields are not simply text, or date, or ID. Check the table below to see which common data types exist in Medallia Experience Cloud and are filterable by Query API.

Alt SetDescription Query API filterable
TEXTStores information as plain text.No
ENUMERATEDMaps a sequence number to every value.Yes
AUTOINDEX_TEXTIt is a list of unique text values with a limit of 200,000.Yes
COMMENTSimilar to TEXT, but with some additional characteristics, like language translation capabilities.No
DATEStores date information, with no time.Yes
TIMEStores time information, with no date.Yes
DATETIMEStores date and time information.Yes
INTEGERStores numbers without decimals.Yes
Restriction: Not suitable for segment filters due to field limits and index restrictions.
FRACTIONALStores numbers with decimals.No
EMAILStores email addresses as text. Some validation is applied.No
UNITThe part of a company respondents interact with, such as accounts or projects.Yes

For details about queries with enumerated field data, see Expanding on enumerated field data.