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
ParameterDescription
includeFields()
Type: Array[String => Boolean]
Default:
n/a
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()
Type: String
Default:
n/a
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()
Type: String or Array[String]
Default:
n/a
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()
Type: integer
Default:
100
Number of objects to return in response. Default is 100, which is also the maximum value.
page()
Type: Array[String => String]
Default:
n/a
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

Reference code

This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.

<?php

// Include Composer autoloader (adjust path if needed)
require_once 'vendor/autoload.php';

use PubNub\PNConfiguration;
use PubNub\PubNub;
use PubNub\Exceptions\PubNubServerException;

// Create configuration with demo keys
$pnConfig = new PNConfiguration();
$pnConfig->setSubscribeKey("demo");
$pnConfig->setPublishKey("demo");
$pnConfig->setUserId("php-app-context-demo");

show all 86 lines

Response

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

ParameterDescription
getData()
Type: Array[PNGetUUIDMetadataResult]
List of uuid metadata results
getTotalCount()
Type: Integer
Number of items returned in the data
getPrev()
Type: String
Random 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()
Type: String
Random 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:

ParameterDescription
getId()
Type: String
Unique user identifier
getName()
Type: String
Display name for the user
getExternalId()
Type: String
User's identifier in an external system
getProfileUrl()
Type: String
The URL of the user's profile picture
getEmail()
Type: String
The user's email address
getCustom()
Type: stdClass
Object 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
ParameterDescription
uuid() *
Type: String
Default:
n/a
Unique user identifier

Basic Usage

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

Response

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

ParameterDescription
getId()
Type: String
Unique user identifier
getName()
Type: String
Display name for the user
getExternalId()
Type: String
User's identifier in an external system
getProfileUrl()
Type: String
The URL of the user's profile picture
getEmail()
Type: String
The user's email address
getCustom()
Type: stdClass
Object 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
ParameterDescription
uuid() *
Type: String
Default:
n/a
Unique user identifier
meta() *
Type: Array or StdClass
Default:
n/a
UUID metadata to set.
ifMatchesEtag
Type: String
Default:
n/a
The 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:

FieldTypeRequiredDescription
name
String
Optional
Display name for the user.
externalId
String
Optional
User's identifier in an external system.
profileUrl
String
Optional
The URL of the user's profile picture.
email
String
Optional
The user's email address.
custom
Array or StdClass
Optional
Object 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:

ParameterDescription
getId()
Type: String
Unique user identifier
getName()
Type: String
Display name for the user
getExternalId()
Type: String
User's identifier in an external system
getProfileUrl()
Type: String
The URL of the user's profile picture
getEmail()
Type: String
The user's email address
getCustom()
Type: stdClass
Object 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
ParameterDescription
uuid() *
Type: String
Default:
n/a
Unique 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
ParameterDescription
includeFields()
Type: Array[String => Boolean]
Default:
n/a
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()
Type: String
Default:
n/a
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()
Type: String or Array[String]
Default:
n/a
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()
Type: integer
Default:
100
Number of objects to return in response. Default is 100, which is also the maximum value.
page()
Type: Array[String => String]
Default:
n/a
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:

ParameterDescription
getData()
Type: Array[PNGetChannelMetadataResult]
List of channel metadata results
getTotalCount()
Type: Integer
Number of items returned in the data
getPrev()
Type: String
Random 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()
Type: String
Random 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:

ParameterDescription
getId()
Type: String
Unique channel identifier
getName()
Type: String
Display name for the channel
getDescription()
Type: String
Description of a channel
getCustom()
Type: stdClass
Object 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
ParameterDescription
channel() *
Type: String
Default:
n/a
Unique channel identifier

Basic Usage

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

Response

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

ParameterDescription
getId()
Type: String
Unique channel identifier
getName()
Type: String
Display name for the channel
getDescription()
Type: String
Description of a channel
getCustom()
Type: stdClass
Object 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
ParameterDescription
channel() *
Type: String
Default:
n/a
Unique channel identifier
meta() *
Type: Array or StdClass
Default:
n/a
Channel metadata to set.
ifMatchesEtag
Type: String
Default:
n/a
The 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

FieldTypeRequiredDescription
name
String
Optional
Display name for the channel.
description
String
Optional
Description of a channel.
custom
Array or StdClass
Optional
Object 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:

ParameterDescription
getId()
Type: String
Unique channel identifier
getName()
Type: String
Display name for the channels
getDescription()
Type: String
Description of a channel
getCustom()
Type: stdClass
Object 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
ParameterDescription
channel() *
Type: String
Default:
n/a
Unique 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
ParameterDescription
uuid() *
Type: String
Default:
n/a
Unique user identifier
include()
Type: PNMembershipIncludes
Default:
n/a
The additional information to include in the membership response.
 → custom
Type: Boolean
Default:
False
Indicates whether custom data should be included in the response.
 → status
Type: Boolean
Default:
False
Indicates whether the status should be included in the response.
 → type
Type: Boolean
Default:
False
Indicates whether the type should be included in the response.
 → total_count
Type: Boolean
Default:
False
Indicates whether the total count should be included in the response.
 → channel
Type: Boolean
Default:
False
Indicates whether the channel ID information should be included in the response.
 → channelCustom
Type: Boolean
Default:
False
Indicates whether custom data for the channel should be included in the response.
 → channelType
Type: Boolean
Default:
False
Indicates whether the type of the channel should be included in the response.
 → channelStatus
Type: Boolean
Default:
False
Indicates whether the status of the channel should be included in the response.
filter()
Type: String
Default:
n/a
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()
Type: String or Array[String]
Default:
n/a
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()
Type: integer
Default:
100
Number of objects to return in response. Default is 100, which is also the maximum value.
page()
Type: Array[String => String]
Default:
n/a
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:

ParameterDescription
getData()
Type: Array[PNMembershipsResultItem]
List of membership metadata results
getTotalCount()
Type: Integer
Number of items returned in the data
getPrev()
Type: String
Random 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()
Type: String
Random 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:

ParameterDescription
getChannel()
Type: PNMembership
Channel metadata
getCustom()
Type: String
stdClass object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The entity tag

Channel is a PNMembership which contains the following fields:

ParameterDescription
getId()
Type: String
Unique channel identifier
getName()
Type: String
Display name for the channel
getDescription()
Type: String
Description of a channel
getCustom()
Type: stdClass
Object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The 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
ParameterDescription
uuid() *
Type: String
Default:
n/a
Unique user identifier
memberships() *
Type: Array[PNChannelMembership]
Default:
n/a
Array of memberships to set.
custom() *
Type: Array or StdClass
Default:
n/a
Object of key-value pairs with supported data types.
include()
Type: PNMembershipIncludes
Default:
n/a
The additional information to include in the membership response.
 → custom
Type: Boolean
Default:
False
Indicates whether custom data should be included in the response.
 → status
Type: Boolean
Default:
False
Indicates whether the status should be included in the response.
 → type
Type: Boolean
Default:
False
Indicates whether the type should be included in the response.
 → total_count
Type: Boolean
Default:
False
Indicates whether the total count should be included in the response.
 → channel
Type: Boolean
Default:
False
Indicates whether the channel ID information should be included in the response.
 → channelCustom
Type: Boolean
Default:
False
Indicates whether custom data for the channel should be included in the response.
 → channelType
Type: Boolean
Default:
False
Indicates whether the type of the channel should be included in the response.
 → channelStatus
Type: Boolean
Default:
False
Indicates whether the status of the channel should be included in the response.
filter()
Type: String
Default:
n/a
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()
Type: String or Array[String]
Default:
n/a
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()
Type: integer
Default:
100
Number of objects to return in response. Default is 100, which is also the maximum value.
page()
Type: Array[String => String]
Default:
n/a
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() *
Type: Array[String or Array]
Default:
n/a
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:

ParameterDescription
getData()
Type: Array[PNMembershipsResultItem]
List of membership metadata results
getTotalCount()
Type: Integer
Number of items returned in the data
getPrev()
Type: String
Random 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()
Type: String
Random 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:

ParameterDescription
getChannel()
Type: PNMembership
Channel metadata
getCustom()
Type: String
stdClass object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The entity tag

Channel is a PNMembership which contains the following fields:

ParameterDescription
getId()
Type: String
Unique channel identifier
getName()
Type: String
Display name for the channel
getDescription()
Type: String
Description of a channel
getCustom()
Type: stdClass
Object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The 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
ParameterDescription
uuid() *
Type: String
Default:
n/a
Unique user identifier.
memberships() *
Type: Array[PNChannelMembership]
Default:
n/a
Array of memberships to remove.
include()
Type: PNMembershipIncludes
Default:
n/a
The additional information to include in the membership response.
 → custom
Type: Boolean
Default:
False
Indicates whether custom data should be included in the response.
 → status
Type: Boolean
Default:
False
Indicates whether the status should be included in the response.
 → type
Type: Boolean
Default:
False
Indicates whether the type should be included in the response.
 → total_count
Type: Boolean
Default:
False
Indicates whether the total count should be included in the response.
 → channel
Type: Boolean
Default:
False
Indicates whether the channel ID information should be included in the response.
 → channelCustom
Type: Boolean
Default:
False
Indicates whether custom data for the channel should be included in the response.
 → channelType
Type: Boolean
Default:
False
Indicates whether the type of the channel should be included in the response.
 → channelStatus
Type: Boolean
Default:
False
Indicates whether the status of the channel should be included in the response.
filter()
Type: String
Default:
n/a
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()
Type: String or Array[String]
Default:
n/a
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()
Type: integer
Default:
100
Number of objects to return in response. Default is 100, which is also the maximum value.
page()
Type: Array[String => String]
Default:
n/a
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() *
Type: Array[String]
Default:
n/a
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:

ParameterDescription
getData()
Type: Array[PNMembershipsResultItem]
List of membership metadata results
getTotalCount()
Type: Integer
Number of items returned in the data
getPrev()
Type: String
Random 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()
Type: String
Random 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:

ParameterDescription
getChannel()
Type: PNMembership
Channel metadata
getCustom()
Type: String
stdClass object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The entity tag

Channel is a PNMembership which contains the following fields:

ParameterDescription
getId()
Type: String
Unique channel identifier
getName()
Type: String
Display name for the channel
getDescription()
Type: String
Description of a channel
getCustom()
Type: stdClass
Object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The 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
ParameterDescription
channel() *
Type: String
Default:
n/a
Unique channel identifier
setChannels() *
Type: Array[String]
Default:
n/a
Array of channels to add to the channel.
removeChannels() *
Type: Array[String]
Default:
n/a
Array of channels to remove from the channel.
setMemberships() *
Type: Array[PNChannelMembership]
Default:
n/a
Array of PNChannelMembership objects to add to the channel.
removeMemberships() *
Type: Array[PNChannelMembership]
Default:
n/a
Array of PNChannelMembership objects to remove from the channel.
custom() *
Type: Array or StdClass
Default:
n/a
Object of key-value pairs with supported data types.
include()
Type: PNMembershipIncludes
Default:
n/a
The additional information to include in the membership response.
 → custom
Type: Boolean
Default:
False
Indicates whether custom data should be included in the response.
 → status
Type: Boolean
Default:
False
Indicates whether the status should be included in the response.
 → type
Type: Boolean
Default:
False
Indicates whether the type should be included in the response.
 → total_count
Type: Boolean
Default:
False
Indicates whether the total count should be included in the response.
 → channel
Type: Boolean
Default:
False
Indicates whether the channel ID information should be included in the response.
 → channelCustom
Type: Boolean
Default:
False
Indicates whether custom data for the channel should be included in the response.
 → channelType
Type: Boolean
Default:
False
Indicates whether the type of the channel should be included in the response.
 → channelStatus
Type: Boolean
Default:
False
Indicates whether the status of the channel should be included in the response.
filter()
Type: String
Default:
n/a
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()
Type: String or Array[String]
Default:
n/a
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()
Type: integer
Default:
100
Number of objects to return in response. Default is 100, which is also the maximum value.
page()
Type: Array[String => String]
Default:
n/a
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:

ParameterDescription
getData()
Type: Array[PNMembershipsResultItem]
List of membership metadata results
getTotalCount()
Type: Integer
Number of items returned in the data
getPrev()
Type: String
Random 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()
Type: String
Random 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:

ParameterDescription
getChannel()
Type: PNMembership
Channel metadata
getCustom()
Type: String
stdClass object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The entity tag

Channel is a PNMembership which contains the following fields:

ParameterDescription
getId()
Type: String
Unique channel identifier
getName()
Type: String
Display name for the channel
getDescription()
Type: String
Description of a channel
getCustom()
Type: stdClass
Object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The 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
ParameterDescription
channel() *
Type: String
Default:
n/a
Unique channel identifier
include()
Type: PNMemberIncludes
Default:
n/a
The additional information to include in the member response.
 → custom
Type: Boolean
Default:
False
Indicates whether custom data should be included in the response.
 → status
Type: Boolean
Default:
False
Indicates whether the status should be included in the response.
 → type
Type: Boolean
Default:
False
Indicates whether the type should be included in the response.
 → total_count
Type: Boolean
Default:
False
Indicates whether the total count should be included in the response.
 → user
Type: Boolean
Default:
False
Indicates whether the user ID information should be included in the response.
 → userCustom
Type: Boolean
Default:
False
Indicates whether custom data for the user should be included in the response.
 → userType
Type: Boolean
Default:
False
Indicates whether the type of the user should be included in the response.
 → userStatus
Type: Boolean
Default:
False
Indicates whether the status of the user should be included in the response.
filter()
Type: String
Default:
n/a
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()
Type: String or Array[String]
Default:
n/a
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()
Type: integer
Default:
100
Number of objects to return in response. Default is 100, which is also the maximum value.
page()
Type: Array[String => String]
Default:
n/a
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:

ParameterDescription
getData()
Type: Array[PNMembersResultItem]
List of member metadata results
getTotalCount()
Type: Integer
Number of items returned in the data
getPrev()
Type: String
Random 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()
Type: String
Random 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:

ParameterDescription
getUUID()
Type: PNMember
UUID metadata
getCustom()
Type: String
stdClass object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The entity tag

Channel is a PNMember which contains the following fields:

ParameterDescription
getId()
Type: String
Unique user identifier
getName()
Type: String
Display name for the user
getExternalId()
Type: String
User's identifier in an external system
getProfileUrl()
Type: String
The URL of the user's profile picture
getEmail()
Type: String
The user's email address
getCustom()
Type: stdClass
Object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The 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
ParameterDescription
channel() *
Type: String
Default:
n/a
Unique channel identifier
uuids() *
Type: Array[String or Array]
Default:
n/a
Array of members to add to the channel. Array can contain strings (uuid only) or arrays/objects (which can include custom data).
custom() *
Type: Array or StdClass
Default:
n/a
Object of key-value pairs with supported data types.
include()
Type: PNMemberIncludes
Default:
n/a
The additional information to include in the member response.
 → custom
Type: Boolean
Default:
False
Indicates whether custom data should be included in the response.
 → status
Type: Boolean
Default:
False
Indicates whether the status should be included in the response.
 → type
Type: Boolean
Default:
False
Indicates whether the type should be included in the response.
 → total_count
Type: Boolean
Default:
False
Indicates whether the total count should be included in the response.
 → user
Type: Boolean
Default:
False
Indicates whether the user ID information should be included in the response.
 → userCustom
Type: Boolean
Default:
False
Indicates whether custom data for the user should be included in the response.
 → userType
Type: Boolean
Default:
False
Indicates whether the type of the user should be included in the response.
 → userStatus
Type: Boolean
Default:
False
Indicates whether the status of the user should be included in the response.
filter()
Type: String
Default:
n/a
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()
Type: String or Array[String]
Default:
n/a
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()
Type: integer
Default:
100
Number of objects to return in response. Default is 100, which is also the maximum value.
page()
Type: Array[String => String]
Default:
n/a
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:

ParameterDescription
getData()
Type: Array[PNMembersResultItem]
List of member metadata results
getTotalCount()
Type: Integer
Number of items returned in the data
getPrev()
Type: String
Random 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()
Type: String
Random 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:

ParameterDescription
getUUID()
Type: PNMember
UUID metadata
getCustom()
Type: String
stdClass object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The entity tag

Channel is a PNMember which contains the following fields:

ParameterDescription
getId()
Type: String
Unique user identifier
getName()
Type: String
Display name for the user
getExternalId()
Type: String
User's identifier in an external system
getProfileUrl()
Type: String
The URL of the user's profile picture
getEmail()
Type: String
The user's email address
getCustom()
Type: stdClass
Object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The 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
ParameterDescription
channel() *
Type: String
Default:
n/a
Unique channel identifier
members() *
Type: PNChannelMember[]
Default:
n/a
Array of members to remove from the channel
include()
Type: PNMemberIncludes
Default:
n/a
The additional information to include in the member response.
 → custom
Type: Boolean
Default:
False
Indicates whether custom data should be included in the response.
 → status
Type: Boolean
Default:
False
Indicates whether the status should be included in the response.
 → type
Type: Boolean
Default:
False
Indicates whether the type should be included in the response.
 → total_count
Type: Boolean
Default:
False
Indicates whether the total count should be included in the response.
 → user
Type: Boolean
Default:
False
Indicates whether the user ID information should be included in the response.
 → userCustom
Type: Boolean
Default:
False
Indicates whether custom data for the user should be included in the response.
 → userType
Type: Boolean
Default:
False
Indicates whether the type of the user should be included in the response.
 → userStatus
Type: Boolean
Default:
False
Indicates whether the status of the user should be included in the response.
filter()
Type: String
Default:
n/a
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()
Type: String or Array[String]
Default:
n/a
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()
Type: integer
Default:
100
Number of objects to return in response. Default is 100, which is also the maximum value.
page()
Type: Array[String => String]
Default:
n/a
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:

ParameterDescription
getData()
Type: Array[PNMembersResultItem]
List of member metadata results
getTotalCount()
Type: Integer
Number of items returned in the data
getPrev()
Type: String
Random 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()
Type: String
Random 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:

ParameterDescription
getUUID()
Type: PNMember
UUID metadata
getCustom()
Type: String
stdClass object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The entity tag

Channel is a PNMember which contains the following fields:

ParameterDescription
getId()
Type: String
Unique user identifier
getName()
Type: String
Display name for the user
getExternalId()
Type: String
User's identifier in an external system
getProfileUrl()
Type: String
The URL of the user's profile picture
getEmail()
Type: String
The user's email address
getCustom()
Type: stdClass
Object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The 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
ParameterDescription
channel() *
Type: String
Default:
n/a
Unique channel identifier
setUuids() *
Type: Array[String]
Default:
n/a
Array of uuids to add to the channel.
removeUuids() *
Type: Array[String]
Default:
n/a
Array of uuids to remove from the channel.
setMembers() *
Type: Array[PNChannelMember]
Default:
n/a
Array of PNChannelMember objects to add to the channel.
removeMembers() *
Type: Array[PNChannelMember]
Default:
n/a
Array of PNChannelMember objects to remove from the channel.
custom() *
Type: Array or StdClass
Default:
n/a
Object of key-value pairs with supported data types.
include()
Type: PNMemberIncludes
Default:
n/a
The additional information to include in the member response.
 → custom
Type: Boolean
Default:
False
Indicates whether custom data should be included in the response.
 → status
Type: Boolean
Default:
False
Indicates whether the status should be included in the response.
 → type
Type: Boolean
Default:
False
Indicates whether the type should be included in the response.
 → total_count
Type: Boolean
Default:
False
Indicates whether the total count should be included in the response.
 → user
Type: Boolean
Default:
False
Indicates whether the user ID information should be included in the response.
 → userCustom
Type: Boolean
Default:
False
Indicates whether custom data for the user should be included in the response.
 → userType
Type: Boolean
Default:
False
Indicates whether the type of the user should be included in the response.
 → userStatus
Type: Boolean
Default:
False
Indicates whether the status of the user should be included in the response.
filter()
Type: String
Default:
n/a
Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here.
sort()
Type: String or Array[String]
Default:
n/a
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()
Type: integer
Default:
100
Number of objects to return in response. Default is 100, which is also the maximum value.
page()
Type: Array[String => String]
Default:
n/a
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:

ParameterDescription
getData()
Type: Array[PNMembersResultItem]
List of member metadata results
getTotalCount()
Type: Integer
Number of items returned in the data
getPrev()
Type: String
Random 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()
Type: String
Random 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:

ParameterDescription
getUUID()
Type: PNMember
UUID metadata
getCustom()
Type: String
stdClass object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The entity tag

Channel is a PNMember which contains the following fields:

ParameterDescription
getId()
Type: String
Unique user identifier
getName()
Type: String
Display name for the user
getExternalId()
Type: String
User's identifier in an external system
getProfileUrl()
Type: String
The URL of the user's profile picture
getEmail()
Type: String
The user's email address
getCustom()
Type: stdClass
Object containing your custom fields
getUpdated()
Type: String
The last updated date and time
getETag()
Type: String
The entity tag
Last updated on