App Context Filtering Language

PubNub SDKs, REST API, and BizOps Workspace allow you to specify conditions for querying and interacting with user, channel, and membership data (collectively called App Context) using a combination of operators and functions.

You can use the filter parameter to query data fields for users, channels, and memberships and get or change that data based on certain conditions.

Read on to learn which App Context data you can filter through and which operators and expressions you can use for this purpose.

This document shows examples of handling data in your applications using different SDK methods. Still, you can refer to the REST API documentation to learn how to directly query PubNub's server data or read BizOps Workspace docs to find out how to filter user and channel data through UI.

Data fields

Here is a list of data fields available for querying and managing users, channels, and channel memberships using PubNub’s App Context Filtering Language.

User data fields

Data fields format

Format of these parameters can vary between REST API, SDKs, and BizOps Workspace.

  • id — Unique user identifier (UUID)
  • name — User's display name
  • externalId — An identifier that links the user to an external system
  • profileUrl — URL to the user's profile picture
  • email — User's email address
  • status — Condition the user is in, like active (some SDKs)
  • type — Category used to classify the user, like SupportAgent (some SDKs)
  • updated — Timestamp of the last update to the user's metadata
  • custom — Any user-specific property (filtering through it is not recommended in SDKs and BizOps Workspace)

Channel data fields

  • id — Unique channel identifier
  • name — Display name of the channel
  • description — Description of the channel
  • status — Condition the channel is in, like archived (some SDKs)
  • type — Category used to classify the channel, like OffTopic (some SDKs)
  • updated — Timestamp of the last update to the channel's metadata
  • custom — Any channel-specific property (filtering through it is not recommended in SDKs and BizOps Workspace)

Channel memberships and members data fields

  • channel.id - Identifier of the channel associated with the membership
  • channel.name — Name of the channel
  • channel.description — Channel description
  • channel.status — Condition the channel is in, like archived (some SDKs)
  • channel.type — Category used to classify the channel, like OffTopic (some SDKs)
  • channel.updated — Timestamp of the last update to the channel's metadata
  • channel.custom - Any channel-specific property (filtering through it is not recommended in SDKs and BizOps Workspace)
  • uuid.id — The UUID of the channel member
  • uuid.name — Name of the channel member
  • uuid.externalId — An identifier that links the channel member to an external system
  • uuid.profileUrl — URL to the channel member's profile picture
  • uuid.email — Channel member's email address
  • uuid.status — Condition the channel member is in, like active (some SDKs)
  • uuid.type — Category used to classify the channel member, like SupportAgent (some SDKs)
  • uuid.updated — Timestamp when the channel member was last updated
  • uuid.custom - Any channel member-specific property (filtering through it is not recommended in SDKs and BizOps Workspace)
  • status — Condition the membership is in
  • type — Category used to classify the membership, like subscription (only REST API)
  • custom — Any membership-specific property (filtering through it is not recommended)

Filtering operators

When retrieving metadata for users or channels, pass a filter parameter, which contains an expression that determines which records to return based on the properties of those records. The filtering language supports basic operators like comparison (==, !=, >, <, >=, <=), logical operators (&&, ||), and the ability to check for presence or patterns using LIKE.

  • == (equal to)
  • != (not equal to)
  • < (less than)
  • > (greater than)
  • <= (less than or equal to)
  • >= (greater than or equal to)
  • && (and)
  • || (or)
  • LIKE (SQL-like pattern matching, supports * as wildcard for string fields)

Query parameters and methods

You can filter App Context data in one of the following ways:

Filter expression components

The filter expression syntax in PubNub's App Context API can be structured into categories that include expressions for logical operations, data referencing tools, literals representing fixed values, and tokens that assist in constructing queries, enabling complex condition formulation and data manipulation in queries.

Expressions and conditions

This category contains the elements that form the logical structure of queries, allowing the definition of conditions and decision-making expressions based on data.

ElementDescriptionSyntax/Example
ExpressionMain building block, evaluates to true or false based on conditionsemail LIKE "*@example.com"
And expressionCombines conditions that must all be true (logical AND)name == "Alice" && email LIKE "*@example.com"
Binary conditionBasic unit for simple or negated conditions!(name == "Alice")
Relational conditionCompares properties to valuesprofileUrl != "http://example.com/default.jpg"

Data references and operators

This category includes the tools for referencing data properties and manipulating them through various operators.

ElementDescriptionSyntax/Example
IdentifierMust start with a letter (A-Z, a-z), $, or _, and allow subsequent characters to include letters, digits (0-9), $, or _.my_user_id, $userID, _user_912710938aa848eda2c3e0c2b583
Property nameCan be an alternative form of an identifier represented by a string enclosed in square brackets. Using square brackets makes most sense for non-regular (custom) fields containing special characters or spaces that are not supported directly with identifiers, but filtering through custom fields is not recommended for SDKs and BizOps Workspace.["name"] == "John" (same as identifier name, but in brackets) or custom["employment-status"] == "valid" (as custom.employment-status == "test" would throw an error due to invalid - character)
Property pathAccesses nested properties using dot notationchannel.name == "general"
Relational operatorOperators to compare properties and values==, !=, <, >, <=, >=, LIKE

Literals and data types

Elements in this category represent specific data values or constants used within filter expressions.

ElementDescriptionSyntax/Example
ValueFixed data values like strings, numbers, booleans, or nullstatus == "active"
StringText values, enclosed in quotes (supports escaped characters)"Hello \"World\""

Characters and tokens

Key single characters and symbols used to construct literals, strings, and structure within the syntax.

ElementDescriptionSyntax/Example
LetterAny alphabetic character from any languagea, Z, é, λ
NumberNumeric values, supports integers, decimals, and scientific notation3.14159, -42, 6.022e23
DigitNumbers from 0 to 90, 9
Hex digitHexadecimal digit used in unicode encoding0, 9, A, F
Double quoteUsed to denote the start and end of strings"This is a string"
Unicode characterAny character valid in the Unicode rangeAny visible character, emoji, etc.
Special characterCharacters that perform special functions in strings. For example, if you want to search for parameters that contain an asterisk, you must escape this special character, like filter: 'name LIKE '*\\**'.\n (new line), \t (tab), \\ (backslash)

Examples

Expression

Get all users whose names start with John.

pubnub.objects.getAllUUIDMetadata({
filter: 'name LIKE "John*"'
})

And expression

Get metadata of channels that include general in names and were updated after January 1st, 2023.

pubnub.objects.getAllChannelMetadata({
filter: 'name LIKE "*general*" && updated >= "2023-01-01T00:00:00Z"'
})

Binary condition

Retrieve all user memberships excluding the channel with ID Channel-001.

pubnub.objects.getMemberships({
uuid: 'user123',
filter: '!(channel.id == "Channel-001")'
})

Relational condition

Find channel members whose last update was before a specific time.

pubnub.objects.getChannelMembers({
channel: "specialEvents",
filter: 'uuid.updated < "2023-01-01T00:00:00Z"'
})

Identifier

Retrieve all users whose name is John.

pubnub.objects.getAllUUIDMetadata({
filter: 'name == "John"'
})

Property name

Retrieve all channels whose descriptions contain support.

pubnub.objects.getAllChannelMetadata({
filter: '["description"] LIKE "*support*"'
})

Property path

Retrieve all user memberships where channel ID starts with user.

pubnub.objects.getMemberships({
uuid: 'user123',
filter: 'channel.id LIKE "user*")'
})

Relational operator

Add to the advancedChannel channel all specified users, but return only those users whose IDs are greater than a certain value (250).

pubnub.objects.setChannelMembers({
channel: "advancedChannel",
uuids: [
{ id: "201" },
{ id: "300" },
{ id: "450" },
{ id: "789" }
],
filter: 'uuid.id > "250"'
});

Value

Get all oldChannel channel members with the inactive status.

pubnub.objects.getChannelMembers({
channel: "oldChannel",
filter: 'uuid.status == "inactive"'
})

String

Get metadata of a channel with a description including escaped characters.

pubnub.objects.getAllChannelMetadata({
filter: 'description == "Hello \\"Gossipers\\""'
})

Letter

Get all users whose names start with J.

pubnub.objects.getAllUUIDMetadata({
filter: 'name LIKE "J*"'
})

Number

Get metadata of channels that were updated after January 1st, 2023.

pubnub.objects.getAllChannelMetadata({
filter: 'updated >= "2023-01-01T00:00:00Z"'
})

Digit

Get all users with IDs that do not contain 8.

pubnub.objects.getAllUUIDMetadata({
filter: '!(id LIKE "*8*")'
})

Hex digit

Retrieve all channels with IDs containing A3F9.

pubnub.objects.getAllChannelMetadata({
filter: 'id LIKE "*A3F9*"'
})

Double quote

Find all channels whose descriptions contain the word VIP.

pubnub.objects.getAllChannelMetadata({
filter: "description LIKE \"*VIP*\""
})

Unicode character

Retrieve all channel descriptions that contain the ❤️ emoji.

pubnub.objects.getAllChannelMetadata({
filter: 'description LIKE "*❤️*"'
})

Special character

Get metadata of a channel with a specific description containing a new line.

pubnub.objects.getAllChannelMetadata({
filter: 'description == "Check out our new deals!\nAvailable for a limited time."'
})
Last updated on