App Context API for PubNub Go 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 set or removed from the database. 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 Go SDK:
pn.GetAllUUIDMetadata().
Include([]pubnub.PNUUIDMetadataIncludeCustom).
Sort(sort).
Limit(int).
Count(bool).
Start(string).
End(string).
Filter(string).
Execute()
Parameter | Type | Required | Description |
---|---|---|---|
Include | []pubnub.PNUUIDMetadataInclude | Optional | 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 | Array | Optional | 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 | int | Optional | Number of objects to return in response. Default is 100 , which is also the maximum value. |
Count | bool | Optional | Request Count to be included in paginated response. By default, Count is omitted. |
Start | string | Optional | 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 | string | Optional | 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. |
Filter | string | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. In addition to custom attributes, the expressions can refer to attributes on associated entities one level deep (that is, the association and its target entities). |
Basic Usage
incl := []pubnub.PNUUIDMetadataInclude{
pubnub.PNUUIDMetadataIncludeCustom,
}
res, status, err := pn.GetAllUUIDMetadata()
.Include(incl)
.Sort(sort)
.Limit(100)
.Count(true)
.Execute()
Response
The GetAllUUIDMetadata()
operation returns a PNGetAllChannelMetadataResponse
which contains the following parameters:
Property Name | Type | Description |
---|---|---|
Data | []PNUUID | Details of type PNUUID are here |
TotalCount | int | Total count of objects without pagination. |
Next | 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. |
Prev | 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. 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:
pn.PNUUIDMetadataInclude().
Include([]pubnub.PNUUIDMetadataIncludeCustom).
Sort(sort).
ID(string).
Execute()
Parameter | Type | Required | Description |
---|---|---|---|
Include | []pubnub.PNUUIDMetadataIncludeCustom | Optional | 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 | Array | Optional | 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'} |
ID | string | Yes | Unique user identifier. If not supplied then current user's uuid is used. |
Basic Usage
id := "testuuid"
incl := []pubnub.PNUUIDMetadataInclude{
pubnub.PNUUIDMetadataIncludeCustom,
}
res, status, err := pn.GetUUIDMetadata().
UUID(id).
Include(incl).
Execute()
fmt.Println(res, status, err)
Response
The GetUUIDMetadata()
operation returns a PNGetUUIDMetadataResponse
which contains the following parameters:
Property Name | Type | Description |
---|---|---|
Data | PNUUID | Details of type PNUUID are here |
Set User Metadata
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:
pn.SetUUIDMetadata().
Include([]pubnub.PNUUIDMetadataIncludeCustom).
Sort(sort).
ID(id).
Name(string).
ExternalID(string).
ProfileURL(string).
Email(string).
Custom(map[string]interface{}).
Execute()
Parameter | Type | Required | Description |
---|---|---|---|
Include | []pubnub.PNUUIDMetadataInclude | Optional | 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 | string | Yes | Unique user identifier. If not supplied then current user's uuid is used. |
Sort | Array | Optional | 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'} |
Name | string | Yes | 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 | map[string]interface | Optional | JSON object of key-value pairs with supported data types. 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
id := "testuuid"
name := "name"
extid := "extid"
purl := "profileurl"
email := "email"
custom := make(map[string]interface{})
custom["a"] = "b"
custom["c"] = "d"
incl := []pubnub.PNUUIDMetadataInclude{
pubnub.PNUUIDMetadataIncludeCustom,
}
res, status, err := pn.SetUUIDMetadata()
show all 24 linesResponse
The SetUUIDMetadata()
operation returns a PNSetUUIDMetadataResponse
which contains the following parameters:
Property Name | Type | Description |
---|---|---|
Data | PNUUID | Details of type PNUUID are here |
PNUUID
Property Name | Type | Description |
---|---|---|
ID | string | Unique user identifier. If not supplied then current user's uuid is used. |
Name | string | Display name for the user. |
ExternalID | string | User's identifier in an external system |
ProfileURL | string | The URL of the user's profile picture |
Email | string | The user's email address. |
Custom | map[string]interface | JSON object of key-value pairs with supported data types. |
Updated | string | Last updated date. |
ETag | string | The ETag. |
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:
pn.RemoveUUIDMetadata().
ID(string).
Execute()
Parameter | Type | Required | Description |
---|---|---|---|
ID | string | Yes | Unique user identifier. If not supplied then current user's uuid is used. |
Basic Usage
id := "testuuid"
res, status, err := pn.RemoveUUIDMetadata()
.UUID(id)
.Execute()
fmt.Println(res, status, err)
Response
The RemoveUUIDMetadata()
operation returns a PNRemoveUUIDMetadataResponse
which contains the following parameters:
Property Name | Type | Description |
---|---|---|
Data | interface | Returns 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.
Method(s)
To Get All Channel Metadata
you can use the following method(s) in the Go SDK:
pn.GetAllChannelMetadata().
Include([]pubnub.PNChannelMetadataInclude).
Sort(sort).
Limit(int).
Count(bool).
Start(string).
End(string).
Filter(string).
Execute()
Parameter | Type | Required | Description |
---|---|---|---|
Include | []pubnub.PNChannelMetadataInclude | Optional | 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 | Array | Optional | 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 | int | Optional | Number of objects to return in response. Default is 100 , which is also the maximum value. |
Count | bool | Optional | Request Count to be included in paginated response. By default, Count is omitted. |
Start | string | Optional | 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 | string | Optional | 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. |
Filter | string | Optional | Expression used to filter the results. Only objects whose properties satisfy the given expression are returned. The filter language is defined here. In addition to custom attributes, the expressions can refer to attributes on associated entities one level deep (that is, the association and its target entities). |
Basic Usage
incl := []pubnub.PNChannelMetadataInclude{
pubnub.PNChannelMetadataIncludeCustom,
}
res, status, err := pn.GetAllChannelMetadata()
.Include(incl)
.Sort(sort)
.Limit(100)
.Count(true)
.Execute()
fmt.Println(res, status, err)
Response
The GetAllChannelMetadata()
operation returns a PNGetAllChannelMetadataResponse
which contains the following parameters:
Property Name | Type | Description |
---|---|---|
Data | []PNChannel | Details of type PNChannel are here |
TotalCount | int | Total count of objects without pagination. |
Next | 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. |
Prev | 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. 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:
pn.GetChannelMetadata().
Include([]pubnub.PNChannelMetadataInclude).
Sort(sort).
ID(string).
Execute()
Parameter | Type | Required | Description |
---|---|---|---|
Include | []pubnub.PNChannelMetadataInclude | Optional | 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 | Array | Optional | 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'} |
ID | string | Yes | Unique user identifier. If not supplied then current user's uuid is used. |
Basic Usage
id := "testchannel"
incl := []pubnub.PNChannelMetadataInclude{
pubnub.PNChannelMetadataIncludeCustom,
}
res, status, err := pn.GetChannelMetadata()
.Include(incl)
.Channel(id)
.Execute()
fmt.Println(res, status, err)
Response
The GetChannelMetadata()
operation returns a PNGetChannelMetadataResponse
which contains the following parameters:
Property Name | Type | Description |
---|---|---|
Data | PNChannel | Details of type PNChannel are here |
Set Channel Metadata
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:
pn.SetChannelMetadata().
Include([]pubnub.PNChannelMetadataInclude).
Sort(sort).
ID(string).
Name(string).
Description(string).
Custom(map[string]interface{}).
Execute()
Parameter | Type | Required | Description |
---|---|---|---|
Include | []pubnub.PNChannelMetadataInclude | Optional | 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 | Array | Optional | 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'} |
ID | string | Yes | Unique user identifier. If not supplied then current user's uuid is used. |
Name | string | Yes | Name of a channel. |
Description | string | Optional | Description of a channel. |
Custom | map[string]interface | Optional | Map of string and interface with supported data types. Values must be scalar only; arrays or objects are not supported. 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
id := "testchannel"
name := "name"
desc := "desc"
custom := make(map[string]interface{}) custom["a"] = "b" custom["c"] = "d"
incl := []pubnub.PNChannelMetadataInclude{
pubnub.PNChannelMetadataIncludeCustom,
}
res, status, err := pn.SetChannelMetadata()
.Include(incl)
.Channel(id)
.Name(name)
.Description(desc)
.Custom(custom)
.Execute()
Response
The SetChannelMetadata()
operation returns a PNSetChannelMetadataResponse
which contains the following parameters:
Property Name | Type | Description |
---|---|---|
Data | PNChannel | Details of type PNChannel are here |
PNChannel
Property Name | Type | Description |
---|---|---|
ID | string | Unique user identifier. If not supplied then current user's uuid is used. |
Name | string | Display name for the user. |
Description | string | Description of a channel. |
Custom | map[string]interface | Map of string and interface with supported data types. Values must be scalar only; arrays or objects are not supported. |
Updated | string | Last updated date. |
ETag | string | The ETag. |
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:
pn.RemoveChannelMetadata().
ID(string).
Execute()
Parameter | Type | Required | Description |
---|---|---|---|
ID | string | Yes | Unique user identifier. If not supplied then current user's uuid is used. |
Basic Usage
id := "testchannel"
res, status, err := pn.RemoveChannelMetadata().Channel(id).Execute()
Response
The RemoveChannelMetadata()
operation returns a PNRemoveChannelMetadataResponse
which contains the following parameters:
Property Name | Type | Description |
---|---|---|
Data | interface | Returns an empty interface. |