App Context API for Go SDK

Starting a new app? Use DataSync

DataSync is the successor to App Context. It covers the same users, channels, and memberships, and adds typed schemas, JSON Patch updates with ETags, field-level projections, and per-class expiry. Refer to the feature-by-feature comparison for details.

DataSync is currently available to new accounts and to accounts that are not actively using App Context. If your keysets already use App Context, keep using it for now. App Context remains fully supported.

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 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. Making a request to set the same data that already exists doesn't trigger an 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.

Required keyset configuration
To get all channel and user metadata, you must uncheck the Disallow Get All Channel Metadata and Disallow Get All User Metadata checkboxes in the App Context section of your keyset configuration in the Admin Portal.

Method(s)​

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

1pn.GetAllUUIDMetadata().
2 Include([]pubnub.PNUUIDMetadataIncludeCustom).
3 Sort(sort).
4 Limit(int).
5 Count(bool).
6 Start(string).
7 End(string).
8 Filter(string).
9 Execute()
* required
ParameterDescription
Include
Type: []pubnub.PNUUIDMetadataInclude
List of additional/complex UUID attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values: pubnub.PNUUIDMetadataIncludeCustom
Sort
Type: Array
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
Limit
Type: int
Number of objects to return. Default/Max: 100.
Count
Type: bool
Whether to include the total count in the paginated response. Default is false.
Start
Type: string
Cursor-based pagination.
End
Type: string
Cursor-based pagination.
Filter
Type: string
Filter expression. Only matching objects are returned. See filtering.

Sample code​

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.
1

Response​

The GetAllUUIDMetadata() operation returns a PNGetAllChannelMetadataResponse which contains the following parameters:

Property NameTypeDescription
Data[]PNUUIDDetails of type PNUUID are here
TotalCountintTotal count of objects without pagination.
NextstringRandom 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.
PrevstringRandom 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. Ignored if the Next parameter is supplied.

Get user metadata​

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

Method(s)​

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

1pn.PNUUIDMetadataInclude().
2 Include([]pubnub.PNUUIDMetadataIncludeCustom).
3 Sort(sort).
4 ID(string).
5 Execute()
* required
ParameterDescription
Include
Type: []pubnub.PNUUIDMetadataIncludeCustom
List of additional/complex UUID attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNUUIDMetadataIncludeCustom
Sort
Type: Array
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
ID *
Type: string
UUID. If not supplied, the current user's UUID is used.

Sample code​

1

Response​

The GetUUIDMetadata() operation returns a PNGetUUIDMetadataResponse which contains the following parameters:

Property NameTypeDescription
DataPNUUIDDetails of type PNUUID are here

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, optionally including the custom data object for each.

Method(s)​

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

1pn.SetUUIDMetadata().
2 Include([]pubnub.PNUUIDMetadataIncludeCustom).
3 Sort(sort).
4 ID(id).
5 Name(string).
6 ExternalID(string).
7 ProfileURL(string).
8 Email(string).
9 Custom(map[string]interface{}).
10 IfMatchETag(string).
11 Execute()
* required
ParameterDescription
Include
Type: []pubnub.PNUUIDMetadataInclude
List of additional/complex UUID attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values: pubnub.PNUUIDMetadataIncludeCustom
ID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.
Sort
Type: Array
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
Name *
Type: string
Display name for the user.
ExternalID
Type: string
User's identifier in an external system
ProfileURL
Type: string
The URL of the user's profile picture
Email
Type: string
The user's email address.
Custom
Type: map[string]interface{}
Custom JSON values. Can be strings, numbers, or booleans. Filtering by Custom isn't supported.
IfMatchETag
Type: string
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.
API limits

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

Sample code​

1

Response​

The SetUUIDMetadata() operation returns a PNSetUUIDMetadataResponse which contains the following parameters:

Property NameTypeDescription
DataPNUUIDDetails of type PNUUID are here

PNUUID​

Property NameTypeDescription
IDstringUnique user identifier. If not supplied then current user's uuid is used.
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.
Custommap[string]interfaceCustom JSON values. Can be strings, numbers, or booleans.
UpdatedstringLast updated date.
ETagstringThe ETag.
StatusstringUser status. Max. 50 characters.
TypestringUser type. Max. 50 characters.

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 Go SDK:

1pn.RemoveUUIDMetadata().
2 ID(string).
3 Execute()
* required
ParameterDescription
ID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.

Sample code​

1

Response​

The RemoveUUIDMetadata() operation returns a PNRemoveUUIDMetadataResponse which contains the following parameters:

Property NameTypeDescription
DatainterfaceReturns an empty interface.

Channel​

Get metadata for all channels​

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

Required keyset configuration
To get all channel and user metadata, you must uncheck the Disallow Get All Channel Metadata and Disallow Get All User Metadata checkboxes in the App Context section of your keyset configuration in the Admin Portal.

Method(s)​

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

1pn.GetAllChannelMetadata().
2 Include([]pubnub.PNChannelMetadataInclude).
3 Sort(sort).
4 Limit(int).
5 Count(bool).
6 Start(string).
7 End(string).
8 Filter(string).
9 Execute()
* required
ParameterDescription
Include
Type: []pubnub.PNChannelMetadataInclude
List of additional/complex space attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNChannelMetadataIncludeCustom
Sort
Type: Array
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
Limit
Type: int
Number of objects to return. Default/Max: 100.
Count
Type: bool
Whether to include the total count in the paginated response. Default is false.
Start
Type: string
Cursor-based pagination.
End
Type: string
Cursor-based pagination.
Filter
Type: string
Filter expression. Only matching objects are returned. See filtering.

Sample code​

1

Response​

The GetAllChannelMetadata() operation returns a PNGetAllChannelMetadataResponse which contains the following parameters:

Property NameTypeDescription
Data[]PNChannelDetails of type PNChannel are here
TotalCountintTotal count of objects without pagination.
NextstringRandom 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.
PrevstringRandom 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. Ignored if the Next parameter is supplied.

Get channel metadata​

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

Method(s)​

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

1pn.GetChannelMetadata().
2 Include([]pubnub.PNChannelMetadataInclude).
3 Sort(sort).
4 ID(string).
5 Execute()
* required
ParameterDescription
Include
Type: []pubnub.PNChannelMetadataInclude
List of additional/complex space attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNChannelMetadataIncludeCustom
Sort
Type: Array
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
ID *
Type: string
UUID. If not supplied, the current user's UUID is used.

Sample code​

1

Response​

The GetChannelMetadata() operation returns a PNGetChannelMetadataResponse which contains the following parameters:

Property NameTypeDescription
DataPNChannelDetails of type PNChannel are here

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, optionally including the custom data object for each.

Method(s)​

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

1pn.SetChannelMetadata().
2 Include([]pubnub.PNChannelMetadataInclude).
3 Sort(sort).
4 ID(string).
5 Name(string).
6 Description(string).
7 Custom(map[string]interface{}).
8 IfMatchETag(string).
9 Execute()
* required
ParameterDescription
Include
Type: []pubnub.PNChannelMetadataInclude
List of additional/complex space attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNChannelMetadataIncludeCustom
Sort
Type: Array
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
ID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.
Name *
Type: string
Name of a channel.
Description
Type: string
Description of a channel.
Custom
Type: map[string]interface
Custom JSON values. Can be strings, numbers, or booleans. Filtering by Custom isn't supported.
IfMatchETag
Type: string
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.
API limits

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

Sample code​

1

Response​

The SetChannelMetadata() operation returns a PNSetChannelMetadataResponse which contains the following parameters:

Property NameTypeDescription
DataPNChannelDetails of type PNChannel are here

PNChannel​

Property NameTypeDescription
IDstringUnique user identifier. If not supplied then current user's uuid is used.
NamestringDisplay name for the user.
DescriptionstringDescription of a channel.
Custommap[string]interfaceCustom JSON values. Can be strings, numbers, or booleans.
UpdatedstringLast updated date.
ETagstringThe ETag.
StatusstringChannel status. Max. 50 characters.
TypestringChannel type. Max. 50 characters.

Other examples​

Iteratively update existing user metadata​
1

Iteratively update existing channel metadata​
1

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 Go SDK:

1pn.RemoveChannelMetadata().
2 ID(string).
3 Execute()
* required
ParameterDescription
ID *
Type: string
Unique user identifier. If not supplied then current user's uuid is used.

Sample code​

1

Response​

The RemoveChannelMetadata() operation returns a PNRemoveChannelMetadataResponse which contains the following parameters:

Property NameTypeDescription
DatainterfaceReturns an empty interface.

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 Go SDK:

1pn.GetMemberships().
2 UUID(string).
3 Include([]pubnub.PNMembershipsInclude).
4 Sort(sort).
5 Limit(int).
6 Count(bool).
7 Start(string).
8 End(string).
9 Filter(string).
10 Execute()
* required
ParameterDescription
UUID *
Type: string
UUID. If not supplied, the current user's UUID is used.
Include
Type: []pubnub.PNMembershipsInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNMembershipsIncludeCustom, pubnub.PNMembershipsIncludeChannel, pubnub.PNMembershipsIncludeChannelCustom
Sort
Type: Array
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
Limit
Type: int
Number of objects to return. Default/Max: 100.
Count
Type: bool
Whether to include the total count in the paginated response. Default is false.
Start
Type: string
Cursor-based pagination.
End
Type: string
Cursor-based pagination.
Filter
Type: string
Filter expression. Only matching objects are returned. See filtering.

Sample code​

1

Response​

The GetMemberships() operation returns a PNGetMembershipsResponse which contains the following parameters:

Property NameTypeDescription
Data[]PNMembershipsDetails of type PNMemberships are here
TotalCountintTotal count of objects without pagination.
NextstringRandom 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.
PrevstringRandom 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. Ignored if the Next parameter is supplied.

PNMemberships​

Property NameTypeDescription
IDstringUnique user identifier. If not supplied then current user's uuid is used.
ChannelPNChannelDetails of type PNChannel are here
Custommap[string]interfaceCustom JSON values. Can be strings, numbers, or booleans.
UpdatedstringLast updated date.
ETagstringThe ETag.
StatusstringStatus of the membership. Max. 50 characters.
TypestringType of the membership. Max. 50 characters.

Set channel memberships​

Set channel memberships for a UUID.

Method(s)​

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

1pn.SetMemberships().
2 UUID(string).
3 Set([]pubnub.PNMembershipsSet).
4 Include([]pubnub.PNMembershipsInclude).
5 Sort(sort).
6 Limit(int).
7 Count(bool).
8 Start(string).
9 End(string).
10 Execute()
* required
ParameterDescription
UUID *
Type: string
UUID. If not supplied, the current user's UUID is used.
Set
Type: pubnub.PNMembershipsSet
Struct of type pubnub.PNMembershipsSet to be added for the specified UUID. In PNMembershipsSet you can set the Channel (of type PNMembershipsChannel - consisting of an ID of string type ) and a Custom map.
Include
Type: []pubnub.PNMembershipsInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNMembershipsIncludeCustom, pubnub.PNMembershipsIncludeChannel, pubnub.PNMembershipsIncludeChannelCustom
Sort
Type: Array
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
Limit
Type: int
Number of objects to return. Default/Max: 100.
Count
Type: bool
Whether to include the total count in the paginated response. Default is false.
Start
Type: string
Cursor-based pagination.
End
Type: string
Cursor-based pagination.
API limits

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

Sample code​

1

Response​

The SetMemberships() operation returns a PNSetMembershipsResponse which contains the following parameters:

Property NameTypeDescription
Data[]PNMembershipsDetails of type PNMemberships are here
TotalCountintTotal count of objects without pagination.
NextstringRandom 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.
PrevstringRandom 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. Ignored if the Next parameter is supplied.

Remove channel memberships​

Remove channel memberships for a UUID.

Method(s)​

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

1pn.RemoveMemberships().
2 UUID(string).
3 Remove([]pubnub.PNMembershipsRemove).
4 Include([]pubnub.PNMembershipsInclude).
5 Limit(int).
6 Count(bool).
7 Start(string).
8 End(string).
9 Execute()
* required
ParameterDescription
UUID *
Type: string
UUID. If not supplied, the current user's UUID is used.
Remove
Type: pubnub.PNMembershipsRemove
Struct of type pubnub.PNMembershipsRemove to be added for the specified UUID. In PNMembershipsRemove you can set the Channel (of type PNMembershipsChannel - consisting of an ID of string type ) and a Custom map.
Include
Type: []pubnub.PNMembershipsInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNMembershipsIncludeCustom, pubnub.PNMembershipsIncludeChannel, pubnub.PNMembershipsIncludeChannelCustom
Limit
Type: int
Number of objects to return. Default/Max: 100.
Count
Type: bool
Whether to include the total count in the paginated response. Default is false.
Start
Type: string
Cursor-based pagination.
End
Type: string
Cursor-based pagination.

Sample code​

1

Response​

The RemoveMemberships() operation returns a PNRemoveMembershipsResponse which contains the following parameters:

Property NameTypeDescription
Data[]PNMembershipsDetails of type PNMemberships are here
TotalCountintTotal count of objects without pagination.
NextstringRandom 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.
PrevstringRandom 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. Ignored if the Next parameter is supplied.

Manage channel memberships​

Manage the specified UUID's memberships. You can Add, Remove, and Update a UUID's memberships.

Method(s)​

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

1pn.ManageMemberships().
2 UUID(string).
3 Set([]pubnub.PNMembershipsSet).
4 Remove([]pubnub.PNMembershipsRemove).
5 Include([]pubnub.PNMembershipsInclude).
6 Sort(sort).
7 Limit(int).
8 Count(bool).
9 Start(string).
10 End(string).
11 Execute()
* required
ParameterDescription
UUID
Type: string
Unique user identifier. If not supplied then current user's Uuid is used.
Set
Type: pubnub.PNMembershipsSet
Struct of type pubnub.PNMembershipsSet to be added for the specified UUID. In PNMembershipsSet you can set the Channel (of type PNMembershipsChannel - consisting of an ID of string type ) and a Custom map.
Remove
Type: pubnub.PNMembershipsRemove
Struct of type pubnub.PNMembershipsRemove to be added for the specified UUID. In PNMembershipsRemove you can set the Channel (of type PNMembershipsChannel - consisting of an ID of string type )
Include
Type: []pubnub.PNMembershipsInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNMembershipsIncludeCustom, pubnub.PNMembershipsIncludeChannel, pubnub.PNMembershipsIncludeChannelCustom
Sort
Type: Array
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
Limit
Type: int
Number of objects to return. Default/Max: 100.
Count
Type: bool
Whether to include the total count in the paginated response. Default is false.
Start
Type: string
Cursor-based pagination.
End
Type: string
Cursor-based pagination.

Sample code​

1

Response​

The ManageMemberships() operation returns a PNManageMembershipsResponse which contains the following parameters:

Property NameTypeDescription
Data[]PNMembershipsDetails of type PNMemberships are here
TotalCountintTotal count of objects without pagination.
NextstringRandom 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.
PrevstringRandom 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. Ignored if the Next parameter is supplied.

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 Go SDK:

1pn.GetChannelMembers().
2 Channel(string).
3 Include(PNChannelMembersInclude).
4 Sort(sort).
5 Limit(int).
6 Count(bool).
7 Start(string).
8 End(string).
9 Filter(string).
10 Execute()
* required
ParameterDescription
Channel *
Type: string
Channel name.
Include
Type: []pubnub.PNChannelMembersInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNChannelMembersIncludeCustom, pubnub.PNChannelMembersIncludeUUID, pubnub.PNChannelMembersIncludeUUIDCustom
Sort
Type: Array
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
Limit
Type: int
Number of objects to return. Default/Max: 100.
Count
Type: bool
Whether to include the total count in the paginated response. Default is false.
Start
Type: string
Cursor-based pagination.
End
Type: string
Cursor-based pagination.
Filter
Type: string
Filter expression. Only matching objects are returned. See filtering.

Sample code​

1

Response​

The GetChannelMembers() operation returns a PNGetChannelMembersResponse which contains the following parameters:

Property NameTypeDescription
Data[]PNChannelMembersDetails of type PNChannelMembers are here
TotalCountintTotal count of objects without pagination.
NextstringRandom 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.
PrevstringRandom 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. Ignored if the Next parameter is supplied.

PNChannelMembers​

Property NameTypeDescription
IDstringUnique user identifier. If not supplied then current user's uuid is used.
UUIDPNUUIDDetails of type PNUUID are here
Custommap[string]interfaceCustom JSON values. Can be strings, numbers, or booleans.
UpdatedstringLast updated date.
ETagstringThe ETag.
StatusstringStatus of the member. Max. 50 characters.
TypestringType of the member. Max. 50 characters.

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 Go SDK:

1pn.SetChannelMembers().
2 Channel(string).
3 Set([]pubnub.PNChannelMembersSet).
4 Include([]pubnub.PNChannelMembersInclude).
5 Sort(sort).
6 Limit(int).
7 Count(bool).
8 Start(string).
9 End(string).
10 Execute()
* required
ParameterDescription
Channel *
Type: string
Channel name.
Set
Type: pubnub.PNChannelMembersSet
Struct of type pubnub.PNChannelMembersSet to be added for the specified space. In PNChannelMembersSet you can set the UUID (of type PNChannelMembersUUID - consisting of an ID of string type ) and a Custom map.
Include
Type: []pubnub.PNChannelMembersInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNChannelMembersIncludeCustom, pubnub.PNChannelMembersIncludeUUID, pubnub.PNChannelMembersIncludeUUIDCustom
Sort
Type: Array
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
Limit
Type: int
Number of objects to return. Default/Max: 100.
Count
Type: bool
Whether to include the total count in the paginated response. Default is false.
Start
Type: string
Cursor-based pagination.
End
Type: string
Cursor-based pagination.
API limits

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

Sample code​

1

Response​

The SetChannelMembers() operation returns a PNSetChannelMembersResponse which contains the following parameters:

Property NameTypeDescription
Data[]PNChannelMembersDetails of type PNChannelMembers are here
TotalCountintTotal count of objects without pagination.
NextstringRandom 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.
PrevstringRandom 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. Ignored if the Next parameter is supplied.

Remove channel members​

Remove members from a Channel.

Method(s)​

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

1pn.RemoveChannelMembers().
2 Channel(string).
3 Remove([]pubnub.PNChannelMembersRemove{}).
4 Include([]pubnub.PNChannelMembersInclude).
5 Limit(int).
6 Count(bool).
7 Start(string).
8 End(string).
9 Execute()
* required
ParameterDescription
channel *
Type: String
Default:
n/a
Name of channel from which members should be fetched.
uuids *
Type: Array
Default:
n/a
List of UUIDs for which metadata associated with each of them in context of channel should be set. Each entry is dictionary with UUID and optional custom fields. custom should be dictionary with simple objects: String and Integer.
sort
Type: Array
Default:
n/a
List of criteria (name of field) which should be used for sorting. Available options are id, name, and updated. Use asc or desc to specify sort direction. For example: {name: 'asc'}
include
Type: Object
Default:
{ count: true }
Additional information which should be included in response. Available options:
  • count- include how many UUID has been associated with metadata.
  • custom - include field with additional information from metadata which has been used during UUID metadata set requests.
filter
Type: String
Default:
n/a
Expression to filter out results basing on specified criteria. For more details on the supported grammar, check here
start
Type: String
Default:
n/a
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.
end
Type: String
Default:
n/a
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. Ignored if the start parameter is supplied.
limit
Type: Integer
Default:
100
Number of objects to return in response. Default is 100, which is also the maximum value.
http_sync
Type: Boolean
Default:
false
Method will be executed asynchronously and will return future, to get its value you can use value method. If set to true, method will return array of envelopes (even if there's only one envelope). For sync methods Envelope object will be returned.
callback
Type: Lambda accepting one parameter
Default:
n/a
Callback that will be called for each envelope. For async methods future will be returned, to retrieve value Envelope object you have to call value method (thread will be locked until the value is returned).

Sample code​

1

Response​

The RemoveChannelMembers() operation returns a PNRemoveChannelMembersResponse which contains the following parameters:

Property NameTypeDescription
Data[]PNChannelMembersDetails of type PNChannelMembers are here
TotalCountintTotal count of objects without pagination.
NextstringRandom 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.
PrevstringRandom 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. Ignored if the Next parameter is supplied.

Manage channel members​

The method Set and Remove channel memberships for a user.

Method(s)​

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

1pn.ManageChannelMembers().
2 Channel(string).
3 Set([]pubnub.PNChannelMembersSet).
4 Remove([]pubnub.PNChannelMembersRemove{}).
5 Include([]pubnub.PNChannelMembersInclude).
6 Sort(sort).
7 Limit(int).
8 Count(bool).
9 Start(string).
10 End(string).
11 Execute()
* required
ParameterDescription
Channel *
Type: string
Channel Name.
Set
Type: pubnub.PNChannelMembersSet
Struct of type pubnub.PNChannelMembersSet to be added for the specified space. In PNChannelMembersSet you can set the UUID (of type PNChannelMembersUUID - consisting of an ID of string type ) and a Custom map.
Remove
Type: pubnub.PNChannelMembersRemove
Struct of type pubnub.PNChannelMembersRemove to be removed for the specified space. In PNChannelMembersRemove you can set the UUID (of type PNChannelMembersUUID - consisting of an ID of string type )
Limit
Type: int
Maximum number of results to return per page. Default 100.
Count
Type: bool
Whether to include the total count in the paginated response. Default is false.
Start
Type: string
Cursor-based pagination.
End
Type: string
Cursor-based pagination.
Sort
Type: Array
Sort by id, name, updated with asc/desc for sort direction (for example, {name: 'asc'}).
Include
Type: []pubnub.PNChannelMembersInclude
List of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes. Available values pubnub.PNChannelMembersIncludeCustom, pubnub.PNChannelMembersIncludeUUID, pubnub.PNChannelMembersIncludeUUIDCustom

Sample code​

1

Response​

The ManageChannelMembers() operation returns a PNManageMembersResponse which contains the following parameters:

Property NameTypeDescription
Data[]PNChannelMembersDetails of type PNChannelMembers are here
TotalCountintTotal count of objects without pagination.
NextstringRandom 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.
PrevstringRandom 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. Ignored if the Next parameter is supplied.

Was this page useful?

Last updated on