App Context API for PHP SDK

This page describes App Context (formerly Objects v2). To upgrade from Objects v1, refer to the migration guide.

App Context provides easy-to-use, serverless storage for user and channel data you need to build innovative, reliable, scalable applications. Use App Context to easily store metadata about your application users and channels, and their membership associations, without the need to stand up your own databases.

PubNub also triggers events when object data is changed: set, updated, or removed from the database. At the same time, making a request to set the same data that already exist, doesn't trigger any event. Clients can receive these events in real time and update their front-end application accordingly.

User

Get Metadata for All Users

Returns a paginated list of UUID Metadata objects, optionally including the custom data object for each.

Method(s)

To Get All UUID Metadata you can use the following method(s) in the PHP SDK:

getAllUUIDMetadata()
->includeFields(Array[String => Boolean])
->filter(String)
->sort(String | Array[String])
->limit(Integer)
->page(Array[String => String])
->sync()
* required
ParameterTypeDefaultDescription
includeFields()Array[String => Boolean]Include respective additional fields in the response. Key value array where keys are one of totalCount or customFields and value is a boolean. Set customFields to fetch custom fields or not. Set totalCount to request totalCount to be included in paginated response. By default, totalCount is omitted.
filter()StringExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()String or Array[String]String or Array of String property names to sort by, and an optional sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or omit to take the default sort direction (ascending). For example: name:asc
limit()integer100Number of objects to return in response. Default is 100, which is also the maximum value.
page()Array[String => String]Use for pagination. Key value array where keys are one of next or prev and value is a random string returned from the server, indicating a specific position in a data set. Set prev to a previously-returned string for fetching the previous page. Set next to a previously-returned string for fetching the next page.

Basic Usage

$response = $pubnub->getAllUUIDMetadata()
->includeFields([ "totalCount" => true, "customFields" => true ])
->sync();

Response

The getAllUUIDMetadata() operation returns a PNGetAllUUIDMetadataResult which contains the following fields:

ParameterTypeDescription
getData()Array[PNGetUUIDMetadataResult]List of uuid metadata results
getTotalCount()IntegerNumber of items returned in the data
getPrev()StringRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
getNext()StringRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.

Data is an array of PNGetUUIDMetadataResult which contains the following fields:

ParameterTypeDescription
getId()StringUnique user identifier
getName()StringDisplay name for the user
getExternalId()StringUser's identifier in an external system
getProfileUrl()StringThe URL of the user's profile picture
getEmail()StringThe user's email address
getCustom()stdClassObject containing your custom fields

Get User Metadata

Returns metadata for the specified UUID, including the custom data object for each.

Method(s)

To Get UUID Metadata you can use the following method(s) in the PHP SDK:

getUUIDMetadata()
->uuid(String)
->sync()
* required
ParameterTypeDefaultDescription
uuid() *StringUnique user identifier

Basic Usage

$response = $pubnub->getUUIDMetadata()
->uuid("uuid")
->sync();

Response

The getUUIDMetadata() operation returns a PNGetUUIDMetadataResult which contains the following fields:

ParameterTypeDescription
getId()StringUnique user identifier
getName()StringDisplay name for the user
getExternalId()StringUser's identifier in an external system
getProfileUrl()StringThe URL of the user's profile picture
getEmail()StringThe user's email address
getCustom()stdClassObject containing your custom fields

Set User Metadata

Unsupported partial updates of custom metadata

The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:

  1. Get the existing metadata and store it locally.
  2. Append the new custom metadata to the existing one.
  3. Set the entire updated custom object.

Set metadata for a UUID in the database, including the custom data object for each.

Method(s)

To Set UUID Metadata you can use the following method(s) in the PHP SDK:

setUUIDMetadata()
->uuid(String)
->meta(Array | StdClass)
->ifMatchesEtag(String)
->sync()
* required
ParameterTypeDefaultDescription
uuid() *StringUnique user identifier
meta() *Array or StdClassUUID metadata to set.
ifMatchesEtagStringThe entity tag to be used to ensure updates only happen if the object hasn't been modified since it was read. Use the eTag you received from an applicable get metadata method to check against the server entity tag. If the eTags don't match, an HTTP 412 error is thrown.

UUID metadata contains the following fields:

* required
FieldTypeDescription
nameStringDisplay name for the user.
externalIdStringUser's identifier in an external system.
profileUrlStringThe URL of the user's profile picture.
emailStringThe user's email address.
customArray or StdClassObject containing your custom fields. App Context filtering language doesn’t support filtering by custom properties.
API limits

To learn about the maximum length of parameters used to set user metadata, refer to REST API docs.

Basic Usage

// using array metadata
$pubnub->setUUIDMetadata()
->uuid("uuid")
->meta([
"name" => "display_name",
"externalId" => "external_id",
"profileUrl" => "profile_url",
"email" => "email_address",
"custom" => [
"a" => "aa",
"b" => "bb"
]
])
->sync();

show all 33 lines

Response

The setUUIDMetadata() operation returns a PNSetUUIDMetadataResult which contains the following fields:

ParameterTypeDescription
getId()StringUnique user identifier
getName()StringDisplay name for the user
getExternalId()StringUser's identifier in an external system
getProfileUrl()StringThe URL of the user's profile picture
getEmail()StringThe user's email address
getCustom()stdClassObject containing your custom fields

Remove User Metadata

Removes the metadata from a specified UUID.

Method(s)

To Remove UUID Metadata you can use the following method(s) in the PHP SDK:

removeUUIDMetadata()
->uuid(String)
->sync()
* required
ParameterTypeDefaultDescription
uuid() *StringUnique user identifier

Basic Usage

$response = $pubnub->removeUUIDMetadata()
->uuid("uuid")
->sync();

Response

Returns a boolean, true for success otherwise false

Channel

Get Metadata for All Channels

Returns a paginated list of Channel Metadata objects, optionally including the custom data object for each.

Method(s)

To Get All Channel Metadata you can use the following method(s) in the PHP SDK:

getAllChannelMetadata()
->includeFields(Array[String => Boolean])
->filter(String)
->sort(String | Array[String])
->limit(Integer)
->page(Array[String => String])
->sync()
* required
ParameterTypeDefaultDescription
includeFields()Array[String => Boolean]Include respective additional fields in the response. Key value array where keys are one of totalCount or customFields and value is a boolean. Set customFields to fetch custom fields or not. Set totalCount to request totalCount to be included in paginated response. By default, totalCount is omitted.
filter()StringExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()String or Array[String]String or Array of String property names to sort by, and an optional sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or omit to take the default sort direction (ascending). For example: name:asc
limit()integer100Number of objects to return in response. Default is 100, which is also the maximum value.
page()Array[String => String]Use for pagination. Key value array where keys are one of next or prev and value is a random string returned from the server, indicating a specific position in a data set. Set prev to a previously-returned string for fetching the previous page. Set next to a previously-returned string for fetching the next page.

Basic Usage

$response = $pubnub->getAllChannelMetadata()
->includeFields([ "totalCount" => true, "customFields" => true ])
->sync();

Response

The getAllChannelMetadata() operation returns a PNGetAllChannelMetadataResult which contains the following fields:

ParameterTypeDescription
getData()Array[PNGetChannelMetadataResult]List of channel metadata results
getTotalCount()IntegerNumber of items returned in the data
getPrev()StringRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
getNext()StringRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.

Data is an array of PNGetChannelMetadataResult which contains the following fields:

ParameterTypeDescription
getId()StringUnique channel identifier
getName()StringDisplay name for the channel
getDescription()StringDescription of a channel
getCustom()stdClassObject containing your custom fields

Get Channel Metadata

Returns metadata for the specified Channel, including the custom data object for each.

Method(s)

To Get Channel Metadata you can use the following method(s) in the PHP SDK:

getChannelMetadata()
->channel(String)
->sync()
* required
ParameterTypeDefaultDescription
channel() *StringUnique channel identifier

Basic Usage

$response = $pubnub->getChannelMetadata()
->channel("channel")
->sync();

Response

The getChannelMetadata() operation returns a PNGetChannelMetadataResult which contains the following fields:

ParameterTypeDescription
getId()StringUnique channel identifier
getName()StringDisplay name for the channel
getDescription()StringDescription of a channel
getCustom()stdClassObject containing your custom fields

Set Channel Metadata

Unsupported partial updates of custom metadata

The value of the custom metadata parameter sent in this method always overwrites the value stored on PubNub servers. If you want to add new custom data to an existing one, you must:

  1. Get the existing metadata and store it locally.
  2. Append the new custom metadata to the existing one.
  3. Set the entire updated custom object.

Set metadata for a Channel in the database, including the custom data object for each.

Method(s)

To Set Channel Metadata you can use the following method(s) in the PHP SDK:

setChannelMetadata()
->channel(String)
->meta(Array | StdClass)
->ifMatchesEtag(String)
->sync()
* required
ParameterTypeDefaultDescription
channel() *StringUnique channel identifier
meta() *Array or StdClassChannel metadata to set.
ifMatchesEtagStringThe entity tag to be used to ensure updates only happen if the object hasn't been modified since it was read. Use the eTag you received from an applicable get metadata method to check against the server entity tag. If the eTags don't match, an HTTP 412 error is thrown.

Channel metadata contains the following fields

* required
FieldTypeDescription
nameStringDisplay name for the channel.
descriptionStringDescription of a channel.
customArray or StdClassObject containing your custom fields. App Context filtering language doesn’t support filtering by custom properties.
API limits

To learn about the maximum length of parameters used to set channel metadata, refer to REST API docs.

Basic Usage

// using array metadata
$pubnub->setChannelMetadata()
->channel("channel")
->meta([
"name" => "display_name",
"description" => "description_of_channel",
"custom" => [
"a" => "aa",
"b" => "bb"
]
])
->sync();

// using stdClass metadata
use stdClass;
show all 29 lines

Response

The setChannelMetadata() operation returns a PNSetChannelMetadataResult which contains the following fields:

ParameterTypeDescription
getId()StringUnique channel identifier
getName()StringDisplay name for the channels
getDescription()StringDescription of a channel
getCustom()stdClassObject containing your custom fields

Other Examples

Iteratively update existing metadata
<?php

set_time_limit(0);

require('vendor/autoload.php');

use PubNub\PNConfiguration;
use PubNub\PubNub;

$pnconf = new PNConfiguration();
$pnconf->setPublishKey("demo");
$pnconf->setSubscribeKey("demo");
$pnconf->setUuid("example");

$pubnub = new PubNub($pnconf);
show all 91 lines

Remove Channel Metadata

Removes the metadata from a specified channel.

Method(s)

To Remove Channel Metadata you can use the following method(s) in the PHP SDK:

removeChannelMetadata()
->channel(String)
->sync()
* required
ParameterTypeDefaultDescription
channel() *StringUnique channel identifier

Basic Usage

$response = $pubnub->removeChannelMetadata()
->channel("channel")
->sync();

Response

Returns a boolean, true for success otherwise false

Channel Memberships

Get Channel Memberships

The method returns a list of channel memberships for a user. This method doesn't return a user's subscriptions.

Method(s)

To Get Memberships you can use the following method(s) in the PHP SDK:

getMemberships()
->uuid(String)
->include(PNMembershipIncludes)
->filter(String)
->sort(String | Array[String])
->limit(Integer)
->page(Array[String => String])
->sync();
* required
ParameterTypeDefaultDescription
uuid() *StringUnique user identifier
include()PNMembershipIncludesn/aThe additional information to include in the membership response.
 → customBooleanFalseIndicates whether custom data should be included in the response.
 → statusBooleanFalseIndicates whether the status should be included in the response.
 → typeBooleanFalseIndicates whether the type should be included in the response.
 → total_countBooleanFalseIndicates whether the total count should be included in the response.
 → channelBooleanFalseIndicates whether the channel ID information should be included in the response.
 → channelCustomBooleanFalseIndicates whether custom data for the channel should be included in the response.
 → channelTypeBooleanFalseIndicates whether the type of the channel should be included in the response.
 → channelStatusBooleanFalseIndicates whether the status of the channel should be included in the response.
filter()StringExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()String or Array[String]String or Array of String property names to sort by, and an optional sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or omit to take the default sort direction (ascending). For example: name:asc
limit()integer100Number of objects to return in response. Default is 100, which is also the maximum value.
page()Array[String => String]Use for pagination. Key value array where keys are one of next or prev and value is a random string returned from the server, indicating a specific position in a data set. Set prev to a previously-returned string for fetching the previous page. Set next to a previously-returned string for fetching the next page.

Basic Usage

$includes = new PNMembershipIncludes();
$includes->channel()->custom()->status()->type();

$response = $pubnub->getMemberships()
->uuid("uuid")
->includes($includes)
->sync();

Response

The getMemberships() operation returns a PNMembershipsResult which contains the following fields:

ParameterTypeDescription
getData()Array[PNMembershipsResultItem]List of membership metadata results
getTotalCount()IntegerNumber of items returned in the data
getPrev()StringRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
getNext()StringRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.

Data is an array of PNMembershipsResultItem which contains the following fields:

ParameterTypeDescription
getChannel()PNMembershipChannel metadata
getCustom()StringstdClass object containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Channel is a PNMembership which contains the following fields:

ParameterTypeDescription
getId()StringUnique channel identifier
getName()StringDisplay name for the channel
getDescription()StringDescription of a channel
getCustom()stdClassObject containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Set Channel Memberships

Set channel memberships for a UUID.

Method(s)

To Set Memberships you can use the following method(s) in the PHP SDK:

setMemberships()
->uuid(String)
->memberships(Array[PNChannelMembership])
->custom(Array | StdClass)
->include(PNMembershipIncludes)
->filter(String)
->sort(String | Array[String])
->limit(Integer)
->page(Array[String => String])
->sync();
* required
ParameterTypeDefaultDescription
uuid() *StringUnique user identifier
memberships() *Array[PNChannelMembership]Array of memberships to set.
custom() *Array or StdClassObject of key-value pairs with supported data types.
include()PNMembershipIncludesn/aThe additional information to include in the membership response.
 → customBooleanFalseIndicates whether custom data should be included in the response.
 → statusBooleanFalseIndicates whether the status should be included in the response.
 → typeBooleanFalseIndicates whether the type should be included in the response.
 → total_countBooleanFalseIndicates whether the total count should be included in the response.
 → channelBooleanFalseIndicates whether the channel ID information should be included in the response.
 → channelCustomBooleanFalseIndicates whether custom data for the channel should be included in the response.
 → channelTypeBooleanFalseIndicates whether the type of the channel should be included in the response.
 → channelStatusBooleanFalseIndicates whether the status of the channel should be included in the response.
filter()StringExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()String or Array[String]String or Array of String property names to sort by, and an optional sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or omit to take the default sort direction (ascending). For example: name:asc
limit()integer100Number of objects to return in response. Default is 100, which is also the maximum value.
page()Array[String => String]Use for pagination. Key value array where keys are one of next or prev and value is a random string returned from the server, indicating a specific position in a data set. Set prev to a previously-returned string for fetching the previous page. Set next to a previously-returned string for fetching the next page.
channels()Array[String or Array]Array of channels to add to membership. Array can contain strings (channel-name only) or objects (which can include custom data).
API limits

To learn about the maximum length of parameters used to set channel membership metadata, refer to REST API docs.

Basic Usage

$includes = new PNMembershipIncludes();
$includes->channel()->channelId()->channelCustom()->channelType()->channelStatus()->custom()->status()->type();

$addMembership = $this->pubnub->setMemberships()
->userId($this->user)
->memberships([
new PNChannelMembership($this->channel1, ['BestDish' => 'Pizza'], 'Admin', 'Active'),
new PNChannelMembership($this->channel2, ['BestDish' => 'Lasagna'], 'Guest', 'Away'),
])
->include($includes)
->sync();

Response

The setMemberships() operation returns a PNMembershipsResult which contains the following fields:

ParameterTypeDescription
getData()Array[PNMembershipsResultItem]List of membership metadata results
getTotalCount()IntegerNumber of items returned in the data
getPrev()StringRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
getNext()StringRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.

Data is an array of PNMembershipsResultItem which contains the following fields:

ParameterTypeDescription
getChannel()PNMembershipChannel metadata
getCustom()StringstdClass object containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Channel is a PNMembership which contains the following fields:

ParameterTypeDescription
getId()StringUnique channel identifier
getName()StringDisplay name for the channel
getDescription()StringDescription of a channel
getCustom()stdClassObject containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Remove Channel Memberships

Remove channel memberships for a UUID.

Method(s)

To Remove Memberships you can use the following method(s) in the PHP SDK:

removeMemberships()
->uuid(String)
->memberships(Array[PNChannelMembership])
->include(PNMembershipIncludes)
->filter(String)
->sort(String | Array[String])
->limit(Integer)
->page(Array[String => String])
->sync();
* required
ParameterTypeDefaultDescription
uuid() *StringUnique user identifier.
memberships() *Array[PNChannelMembership]Array of memberships to remove.
include()PNMembershipIncludesn/aThe additional information to include in the membership response.
 → customBooleanFalseIndicates whether custom data should be included in the response.
 → statusBooleanFalseIndicates whether the status should be included in the response.
 → typeBooleanFalseIndicates whether the type should be included in the response.
 → total_countBooleanFalseIndicates whether the total count should be included in the response.
 → channelBooleanFalseIndicates whether the channel ID information should be included in the response.
 → channelCustomBooleanFalseIndicates whether custom data for the channel should be included in the response.
 → channelTypeBooleanFalseIndicates whether the type of the channel should be included in the response.
 → channelStatusBooleanFalseIndicates whether the status of the channel should be included in the response.
filter()StringExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()String or Array[String]String or Array of String property names to sort by, and an optional sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or omit to take the default sort direction (ascending). For example: name:asc
limit()integer100Number of objects to return in response. Default is 100, which is also the maximum value.
page()Array[String => String]Use for pagination. Key value array where keys are one of next or prev and value is a random string returned from the server, indicating a specific position in a data set. Set prev to a previously-returned string for fetching the previous page. Set next to a previously-returned string for fetching the next page.
channels()Array[String]Array of channels to remove from membership.

Basic Usage

$includes = new PNMembershipIncludes();
$includes->channel()->channelId()->channelCustom()->channelType()->channelStatus()->custom()->status()->type();

$removeMembership = $this->pubnub->removeMemberships()
->userId($this->user)
->memberships([
new PNChannelMembership($this->channel1, ['BestDish' => 'Pizza'], 'Admin', 'Active'),
new PNChannelMembership($this->channel2, ['BestDish' => 'Lasagna'], 'Guest', 'Away'),
])
->include($includes)
->sync();

Response

The removeMemberships() operation returns a PNMembershipsResult which contains the following fields:

ParameterTypeDescription
getData()Array[PNMembershipsResultItem]List of membership metadata results
getTotalCount()IntegerNumber of items returned in the data
getPrev()StringRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
getNext()StringRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.

Data is an array of PNMembershipsResultItem which contains the following fields:

ParameterTypeDescription
getChannel()PNMembershipChannel metadata
getCustom()StringstdClass object containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Channel is a PNMembership which contains the following fields:

ParameterTypeDescription
getId()StringUnique channel identifier
getName()StringDisplay name for the channel
getDescription()StringDescription of a channel
getCustom()stdClassObject containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Manage Channel Memberships

Manage the members of a channel.

To Manage Channel Memberships you can use the following method(s) in the PHP SDK:

manageMembers()
->channel(String)
->setChannels(Array[String])
->removeChannels(Array[String])
->setMemberships(Array[PNChannelMembership])
->removeMemberships(Array[PNChannelMembership])
->custom(Array | StdClass)
->include(PNMemberIncludes)
->filter(String)
->sort(String | Array[String])
->limit(Integer)
->page(Array[String => String])
->sync();
* required
ParameterTypeDefaultDescription
channel() *StringUnique channel identifier
setChannels() *Array[String]Array of channels to add to the channel.
removeChannels() *Array[String]Array of channels to remove from the channel.
setMemberships() *Array[PNChannelMembership]Array of PNChannelMembership objects to add to the channel.
removeMemberships() *Array[PNChannelMembership]Array of PNChannelMembership objects to remove from the channel.
custom() *Array or StdClassObject of key-value pairs with supported data types.
include()PNMembershipIncludesn/aThe additional information to include in the membership response.
 → customBooleanFalseIndicates whether custom data should be included in the response.
 → statusBooleanFalseIndicates whether the status should be included in the response.
 → typeBooleanFalseIndicates whether the type should be included in the response.
 → total_countBooleanFalseIndicates whether the total count should be included in the response.
 → channelBooleanFalseIndicates whether the channel ID information should be included in the response.
 → channelCustomBooleanFalseIndicates whether custom data for the channel should be included in the response.
 → channelTypeBooleanFalseIndicates whether the type of the channel should be included in the response.
 → channelStatusBooleanFalseIndicates whether the status of the channel should be included in the response.
filter()StringExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()String or Array[String]String or Array of String property names to sort by, and an optional sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or omit to take the default sort direction (ascending). For example: name:asc
limit()integer100Number of objects to return in response. Default is 100, which is also the maximum value.
page()Array[String => String]Use for pagination. Key value array where keys are one of next or prev and value is a random string returned from the server, indicating a specific position in a data set. Set prev to a previously-returned string for fetching the previous page. Set next to a previously-returned string for fetching the next page.

Basic Usage

$response = $pubnub->manageMemberships()
->channel("channel")
->setChannels(["channel1", "channel2"])
->removeChannels(["channel3"])
->sync();

Response

The manageMemberships() operation returns a PNMembershipsResult which contains the following fields:

ParameterTypeDescription
getData()Array[PNMembershipsResultItem]List of membership metadata results
getTotalCount()IntegerNumber of items returned in the data
getPrev()StringRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
getNext()StringRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.

Data is an array of PNMembershipsResultItem which contains the following fields:

ParameterTypeDescription
getChannel()PNMembershipChannel metadata
getCustom()StringstdClass object containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Channel is a PNMembership which contains the following fields:

ParameterTypeDescription
getId()StringUnique channel identifier
getName()StringDisplay name for the channel
getDescription()StringDescription of a channel
getCustom()stdClassObject containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Channel Members

Get Channel Members

The method returns a list of members in a channel. The list will include user metadata for members that have additional metadata stored in the database.

Method(s)

To Get Channel Members you can use the following method(s) in the PHP SDK:

getMembers()
->channel(String)
->include(PNMemberIncludes)
->filter(String)
->sort(String | Array[String])
->limit(Integer)
->page(Array[String => String])
->sync();
* required
ParameterTypeDefaultDescription
channel() *StringUnique channel identifier
include()PNMemberIncludesn/aThe additional information to include in the member response.
 → customBooleanFalseIndicates whether custom data should be included in the response.
 → statusBooleanFalseIndicates whether the status should be included in the response.
 → typeBooleanFalseIndicates whether the type should be included in the response.
 → total_countBooleanFalseIndicates whether the total count should be included in the response.
 → userBooleanFalseIndicates whether the user ID information should be included in the response.
 → userCustomBooleanFalseIndicates whether custom data for the user should be included in the response.
 → userTypeBooleanFalseIndicates whether the type of the user should be included in the response.
 → userStatusBooleanFalseIndicates whether the status of the user should be included in the response.
filter()StringExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()String or Array[String]String or Array of String property names to sort by, and an optional sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or omit to take the default sort direction (ascending). For example: name:asc
limit()integer100Number of objects to return in response. Default is 100, which is also the maximum value.
page()Array[String => String]Use for pagination. Key value array where keys are one of next or prev and value is a random string returned from the server, indicating a specific position in a data set. Set prev to a previously-returned string for fetching the previous page. Set next to a previously-returned string for fetching the next page.

Basic Usage

$includes = new PNMemberIncludes();
$includes->user()->custom()->status();

$response = $pubnub->getMembers()
->channel("channel")
->includes($includes)
->sync();

Response

The getMembers() operation returns a PNMembersResult which contains the following fields:

ParameterTypeDescription
getData()Array[PNMembersResultItem]List of member metadata results
getTotalCount()IntegerNumber of items returned in the data
getPrev()StringRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
getNext()StringRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.

Data is an array of PNMembersResultItem which contains the following fields:

ParameterTypeDescription
getUUID()PNMemberUUID metadata
getCustom()StringstdClass object containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Channel is a PNMember which contains the following fields:

ParameterTypeDescription
getId()StringUnique user identifier
getName()StringDisplay name for the user
getExternalId()StringUser's identifier in an external system
getProfileUrl()StringThe URL of the user's profile picture
getEmail()StringThe user's email address
getCustom()stdClassObject containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Set Channel Members

This method sets members in a channel.

Method(s)

To Set Channel Members you can use the following method(s) in the PHP SDK:

setMembers()
->channel(String)
->uuids(Array[String | Array])
->custom(Array | StdClass)
->include(PNMemberIncludes)
->filter(String)
->sort(String | Array[String])
->limit(Integer)
->page(Array[String => String])
->sync();
* required
ParameterTypeDefaultDescription
channel() *StringUnique channel identifier
uuids() *Array[String or Array]Array of members to add to the channel. Array can contain strings (uuid only) or arrays/objects (which can include custom data).
custom() *Array or StdClassObject of key-value pairs with supported data types.
include()PNMemberIncludesn/aThe additional information to include in the member response.
 → customBooleanFalseIndicates whether custom data should be included in the response.
 → statusBooleanFalseIndicates whether the status should be included in the response.
 → typeBooleanFalseIndicates whether the type should be included in the response.
 → total_countBooleanFalseIndicates whether the total count should be included in the response.
 → userBooleanFalseIndicates whether the user ID information should be included in the response.
 → userCustomBooleanFalseIndicates whether custom data for the user should be included in the response.
 → userTypeBooleanFalseIndicates whether the type of the user should be included in the response.
 → userStatusBooleanFalseIndicates whether the status of the user should be included in the response.
filter()StringExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()String or Array[String]String or Array of String property names to sort by, and an optional sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or omit to take the default sort direction (ascending). For example: name:asc
limit()integer100Number of objects to return in response. Default is 100, which is also the maximum value.
page()Array[String => String]Use for pagination. Key value array where keys are one of next or prev and value is a random string returned from the server, indicating a specific position in a data set. Set prev to a previously-returned string for fetching the previous page. Set next to a previously-returned string for fetching the next page.
API limits

To learn about the maximum length of parameters used to set channel members metadata, refer to REST API docs.

Basic Usage

$includes = new PNMemberIncludes();
$includes->user()->userId()->userCustom()->userType()->userStatus()->custom()->status()->type();

$addMembers = $this->pubnub->setMembers()
->channel($this->channel)
->members([
new PNChannelMember($this->userName1, ['BestDish' => 'Pizza'], 'Svensson', 'Active'),
new PNChannelMember($this->userName2, ['BestDish' => 'Lasagna'], 'Baconstrips', 'Retired'),
])
->include($includes)
->sync();

Response

The setMembers() operation returns a PNMembersResult which contains the following fields:

ParameterTypeDescription
getData()Array[PNMembersResultItem]List of member metadata results
getTotalCount()IntegerNumber of items returned in the data
getPrev()StringRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
getNext()StringRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.

Data is an array of PNMembersResultItem which contains the following fields:

ParameterTypeDescription
getUUID()PNMemberUUID metadata
getCustom()StringstdClass object containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Channel is a PNMember which contains the following fields:

ParameterTypeDescription
getId()StringUnique user identifier
getName()StringDisplay name for the user
getExternalId()StringUser's identifier in an external system
getProfileUrl()StringThe URL of the user's profile picture
getEmail()StringThe user's email address
getCustom()stdClassObject containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Remove Channel Members

Remove members from a Channel.

Method(s)

To Remove Channel Members you can use the following method(s) in the PHP SDK:

removeMembers()
->channel(String)
->members(PNChannelMember[])
->include(PNMemberIncludes)
->filter(String)
->sort(String | Array[String])
->limit(Integer)
->page(Array[String => String])
->sync();
* required
ParameterTypeDefaultDescription
channel() *StringUnique channel identifier
members() *PNChannelMember[]Array of members to remove from the channel
include()PNMemberIncludesn/aThe additional information to include in the member response.
 → customBooleanFalseIndicates whether custom data should be included in the response.
 → statusBooleanFalseIndicates whether the status should be included in the response.
 → typeBooleanFalseIndicates whether the type should be included in the response.
 → total_countBooleanFalseIndicates whether the total count should be included in the response.
 → userBooleanFalseIndicates whether the user ID information should be included in the response.
 → userCustomBooleanFalseIndicates whether custom data for the user should be included in the response.
 → userTypeBooleanFalseIndicates whether the type of the user should be included in the response.
 → userStatusBooleanFalseIndicates whether the status of the user should be included in the response.
filter()StringExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()String or Array[String]String or Array of String property names to sort by, and an optional sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or omit to take the default sort direction (ascending). For example: name:asc
limit()integer100Number of objects to return in response. Default is 100, which is also the maximum value.
page()Array[String => String]Use for pagination. Key value array where keys are one of next or prev and value is a random string returned from the server, indicating a specific position in a data set. Set prev to a previously-returned string for fetching the previous page. Set next to a previously-returned string for fetching the next page.

Basic Usage

$includes = new PNMemberIncludes();
$includes->user()->userId()->userCustom()->userType()->userStatus()->custom()->status()->type();

$removeMembers = $this->pubnub->removeMembers()
->channel($this->channel)
->members([
new PNChannelMember($this->userName1, ['BestDish' => 'Pizza'], 'Svensson', 'Active'),
new PNChannelMember($this->userName2, ['BestDish' => 'Lasagna'], 'Baconstrips', 'Retired'),
])
->include($includes)
->sync();

Response

The removeMembers() operation returns a PNMembersResult which contains the following fields:

ParameterTypeDescription
getData()Array[PNMembersResultItem]List of member metadata results
getTotalCount()IntegerNumber of items returned in the data
getPrev()StringRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
getNext()StringRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.

Data is an array of PNMembersResultItem which contains the following fields:

ParameterTypeDescription
getUUID()PNMemberUUID metadata
getCustom()StringstdClass object containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Channel is a PNMember which contains the following fields:

ParameterTypeDescription
getId()StringUnique user identifier
getName()StringDisplay name for the user
getExternalId()StringUser's identifier in an external system
getProfileUrl()StringThe URL of the user's profile picture
getEmail()StringThe user's email address
getCustom()stdClassObject containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Manage Channel Members

Manage the members of a channel.

To Manage Channel Members you can use the following method(s) in the PHP SDK:

manageMembers()
->channel(String)
->setUuids(Array[String])
->removeUuids(Array[String])
->setMembers(Array[PNChannelMember])
->removeMembers(Array[PNChannelMember])
->custom(Array | StdClass)
->include(PNMemberIncludes)
->filter(String)
->sort(String | Array[String])
->limit(Integer)
->page(Array[String => String])
->sync();
* required
ParameterTypeDefaultDescription
channel() *StringUnique channel identifier
setUuids() *Array[String]Array of uuids to add to the channel.
removeUuids() *Array[String]Array of uuids to remove from the channel.
setMembers() *Array[PNChannelMember]Array of PNChannelMember objects to add to the channel.
removeMembers() *Array[PNChannelMember]Array of PNChannelMember objects to remove from the channel.
custom() *Array or StdClassObject of key-value pairs with supported data types.
include()PNMemberIncludesn/aThe additional information to include in the member response.
 → customBooleanFalseIndicates whether custom data should be included in the response.
 → statusBooleanFalseIndicates whether the status should be included in the response.
 → typeBooleanFalseIndicates whether the type should be included in the response.
 → total_countBooleanFalseIndicates whether the total count should be included in the response.
 → userBooleanFalseIndicates whether the user ID information should be included in the response.
 → userCustomBooleanFalseIndicates whether custom data for the user should be included in the response.
 → userTypeBooleanFalseIndicates whether the type of the user should be included in the response.
 → userStatusBooleanFalseIndicates whether the status of the user should be included in the response.
filter()StringExpression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()String or Array[String]String or Array of String property names to sort by, and an optional sort direction. Available options are id, name, and updated. Use asc or desc to specify sort direction, or omit to take the default sort direction (ascending). For example: name:asc
limit()integer100Number of objects to return in response. Default is 100, which is also the maximum value.
page()Array[String => String]Use for pagination. Key value array where keys are one of next or prev and value is a random string returned from the server, indicating a specific position in a data set. Set prev to a previously-returned string for fetching the previous page. Set next to a previously-returned string for fetching the next page.

Basic Usage

$response = $pubnub->manageMembers()
->channel("channel")
->setUuids(["uuid1", "uuid2"])
->removeUuids(["uuid3"])
->sync();

Response

The manageMembers() operation returns a PNMembersResult which contains the following fields:

ParameterTypeDescription
getData()Array[PNMembersResultItem]List of member metadata results
getTotalCount()IntegerNumber of items returned in the data
getPrev()StringRandom string returned from the server, indicating a specific position in a data set. Used for backward pagination, it fetches the previous page, enabling access to earlier data.
getNext()StringRandom string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.

Data is an array of PNMembersResultItem which contains the following fields:

ParameterTypeDescription
getUUID()PNMemberUUID metadata
getCustom()StringstdClass object containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag

Channel is a PNMember which contains the following fields:

ParameterTypeDescription
getId()StringUnique user identifier
getName()StringDisplay name for the user
getExternalId()StringUser's identifier in an external system
getProfileUrl()StringThe URL of the user's profile picture
getEmail()StringThe user's email address
getCustom()stdClassObject containing your custom fields
getUpdated()StringThe last updated date and time
getETag()StringThe entity tag
Last updated on