Developer

Insights

Using filters

The AnywhereNow Insights API provides the ability to use the $filter query parameter to easily retrieve a subset of a collection. This expression, when specified with the $filter parameter, is evaluated for each resource in the collection, and only those items where the expression evaluates to true are included in the response. Any resources for which the expression evaluates to false or to null are omitted from the response, ensuring that only the data that you are looking for is returned.

Operators and functions supported in filter expressions

The following table outlines the operators and functions supported by the AnywhereNow Insights API:

Operator type

Operator

Equality operators

  • Equals (eq)

  • Not equals (ne)

  • Logical negation (not)

  • In (in)

Relational operators

  • Less than (lt)

  • Greater than (gt)

  • Less than or equal to (le)

  • Greater than or equal to (ge)

Conditional operators

  • And (and)

  • Or (or)

Functions

  • Starts with (startsWith)

  • Ends with (endsWith)

  • Contains (contains)

Using the $filter query parameter is a powerful way to retrieve a subset of data from the AnywhereNow Insights API. It allows users to create complex expressions that can be used to filter out unwanted data. This makes it easier to find the data that is needed, without having to manually search through large datasets.

Useful filter query operator to get started

This table provides examples of how to use the $filter query parameter:

Description

Example

Get all Agents

GET /Endpoints?$filter=Role eq 'Agent'

Get all Endpoints that contains the name Learn

GET ~/Endpoints?$filter=contains(name,'Learn')

Get all Dialogues before 1/1/2024.

GET ~/Dialogues?$filter=startTimestamp lt 2024-01-01T00:00:00Z

Get all Dialogues after 1/1/2023.

GET ~/Dialogues?$filter=startTimestamp ge 2023-01-01T00:00:00Z

Get all Dialogues in May 2023.

GET ~/Dialogues?$filter=startTimestamp ge 2023-05-01T00:00:00Z AND startTimestamp lt 2023-05-01T00:00:00Z

Count all Dialogues that are Accepted and within SLA.

GET ~/Dialogues/$count?$filter=ActionType eq 'Accepted' AND DurationType eq 'InSla'

Get all Agent with a name that start with an A

GET /Endpoints?$filter=Role eq 'Agent' and startswith(DisplayName,'A')

How to Utilize the OData Filter Query Parameter

This article provides examples of how to use the $filter OData query parameter and its associated operators. These examples are intended to serve as a guide and do not constitute a comprehensive list of all possible uses of $filter.

Operator

Syntax

eq

~/Endpoints?$filter=Role eq 'Agent'

not

~/Endpoints?$filter=not(Role eq 'Agent')

ne

~/Endpoints?$filter=Role ne 'Agent'

startsWith

~/Endpoints?$filter=startsWith(Displayname, 'Keith')

endsWith

~/Endpoints?$filter=endsWith(Displayname, 'Sanders')

in

~/Dialogues?$filter=AgentId in ('c7c9255a-3261-46cf-f6ee-08db97e9fe64', '3fa85f64-5717-4562-b3fc-2c963f66afa6')

le

~/Dialogues?$filter=startTimestamp le 2024-01-01T00:00:00Z

ge

~/Dialogues?$filter=startTimestamp ge 2023-01-01T00:00:00Z

not and endsWith

~/Users?$filter=not(startsWith(Displayname, 'Keith'))

not and startsWith

~/Users?$filter=not(startsWith(Displayname, 'Keith'))

not and eq

~/Users?$filter=not(Role eq 'Agent')

not and in

~/Dialogues?$filter=not(AgentId in ('c7c9255a-3261-46cf-f6ee-08db97e9fe64', '3fa85f64-5717-4562-b3fc-2c963f66afa6'))

contains

~/Users?$filter=contains(displayName,'| Contoso')