UnityUnity V4 Objects (BETA) API Reference for Realtime Apps

 

These docs are for PubNub 4.x for Unity which is our latest and greatest! For the docs of the older versions of the SDK, please check PubNub 3.x for Unity.

If you have questions about the PubNub for Unity SDK, please contact us at support@pubnub.com.

Creates a user with the specified properties. Returns the created user object, optionally including the user's custom data object.

To Create a User you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    IDstringYesThe user ID. Must be unique, and is limited to 36 characters.
    NamestringYesDisplay name for the user. Maximum 200 characters.
    ExternalIDstringOptionalUser's identifier in an external system
    ProfileURLstringOptionalThe URL of the user's profile picture
    EmailstringOptionalThe user's email address. Maximum 80 characters.
    CustomDictionary<string, object>OptionalDictionary object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported.
    IncludePNUserSpaceInclude[]OptionalList of additional/complex user attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes.
PNUserSpaceInclude[] include = new PNUserSpaceInclude[]{PNUserSpaceInclude.PNUserSpaceCustom};
Dictionary<string, object> userCustom = new Dictionary<string, object>();
userCustom.Add("usercustomkey1", "ucv1");
userCustom.Add("usercustomkey2", "ucv2");

pubnub.CreateUser().Email("email@email.com").ExternalID("externalID").Name(name).ID("user-1").Include(include).Custom(userCustom).ProfileURL("profileURL").Async((result, status) => {        
        if (!status.Error) {
           //PNUserResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }
});
The CreateUser() operation returns a PNUserResult which contains the following parameters:
Property NameTypeDescription
IDstringThe user ID.
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.
CustomDictionary<string, object>Dictionary object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported.
CreatedstringCreate date.
UpdatedstringLast updated date.
ETagstringThe ETag.

Updates a user with the specified properties. Returns the updated user object, optionally including the user's custom data object.

To Update a User you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    IDstringYesUnique identifier of the user to be updated. You cannot change the user ID.
    NamestringYesDisplay name for the user. Maximum 200 characters.
    ExternalIDstringOptionalUser's identifier in an external system.
    ProfileURLstringOptionalThe URL of the user's profile picture.
    EmailstringOptionalThe user's email address. Maximum 80 characters.
    CustomDictionary<string, object>OptionalDictionary object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported.
    IncludePNUserSpaceInclude[]OptionalList of additional/complex user attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes.
pubnubObjects.UpdateUser().Email("email2@email.com").ExternalID("externalID2").Name("John Doe Update").ID("user-1").ProfileURL("profileURL2").Async((result, status) => {
        if (!status.Error) {
           //PNUserResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }
});
The UpdateUser() operation returns a PNUserResult. Details of type PNUserResult are here.

Deletes the specified user object.

To Delete a User you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    IDstringYesID of the user to delete.
pubnubObjects.DeleteUser().ID("user-1").Async((result, status) => {
        if (!status.Error) {
           //PNDeleteUserResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }

});
The DeleteUser() operation returns a PNDeleteUserResult which returns an empty object.

Returns a paginated list of user objects, optionally including each user's custom data object.

To Get Users you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    Count booleanOptionalRequest TotalCount to be included in paginated response. Default false
    Include PNUserSpaceInclude[]OptionalList of additional/complex user attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes.
    LimitintOptionalMaximum number of results to return per page. Default 100.
    StartstringOptionalPreviously-returned cursor bookmark for fetching the next page.
    EndstringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
    FilterstringOptionalExpression 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).
pubnub.GetUsers().Async((result, status) => {
        if (!status.Error) {
           //PNGetUsersResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }	
});
The GetUsers() operation returns a PNGetUsersResult which contains the following parameters:
Property NameTypeDescription
DataList<PNUserResult>Details of PNUserResult are here.
TotalCountintTotal count of objects without pagination.
NextstringCursor bookmark for fetching next page.
PrevstringCursor bookmark for fetching prev page.

Returns the specified user object, optionally including the user's custom data object.

To Get User you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    IDstringYesThe ID of the user to retrieve.
    Include PNUserSpaceInclude[]OptionalList of additional/complex user attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes.
PNUserSpaceInclude[] include = new PNUserSpaceInclude[]{PNUserSpaceInclude.PNUserSpaceCustom};
pubnub.GetUser().ID("user-1").Include(include).Async((result, status) => {
        if (!status.Error) {
           //PNUserResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }

});
The GetUser() operation returns a PNUserResult. Details of type PNUserResult are here.

Creates a space with the specified properties. Returns the created space object, optionally including the space's custom data object.

To Create a Space you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    ID stringYesUnique identifier of the space.
    Name stringYesDisplay name of the space.
    Description stringOptionalDescription of the space.
    CustomDictionary<string, object>OptionalDictionary object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported.
    IncludePNUserSpaceInclude[]OptionalList of additional/complex user attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes.
PNUserSpaceInclude[] include = new PNUserSpaceInclude[]{PNUserSpaceInclude.PNUserSpaceCustom};
Dictionary<string, object> spaceCustom = new Dictionary<string, object>();
spaceCustom.Add("spacecustomkey1", "scv1");
spaceCustom.Add("spacecustomkey2", "scv2");

pubnub.CreateSpace().Name("space-name").ID("space-id").Include(include).Custom(spaceCustom).Description("space-desc").Async((result, status) => {
        if (!status.Error) {
           //PNSpaceResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }

});
The CreateSpace() operation returns a PNSpaceResult which contains the following parameters:
Property NameTypeDescription
IDstringThe space ID.
NamestringDisplay name for the space.
DescriptionstringDescription of the space.
CustomDictionary<string, object>Dictionary object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported.
CreatedstringCreated date.
UpdatedstringLast updated date.
ETagstringThe ETag.

Updates a space with the specified properties. Returns the updated space object, optionally including the space's custom data object.

To Update a Space you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    ID stringYesUnique identifier of the space to be updated. You cannot change the space ID.
    Name stringYesDisplay name of the space.
    Description stringOptionalDescription of the space.
    CustomDictionary<string, object>OptionalDictionary object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported.
    IncludePNUserSpaceInclude[]OptionalList of additional/complex user attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes.
pubnubObjects.UpdateSpace().Description("spacedesc2").Name("spacename2").ID("space-id").Async((result, status) => {
        if (!status.Error) {
           //PNSpaceResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }

});
The UpdateSpace() operation returns a PNSpaceResult. Details of type PNSpaceResult are here.

Deletes the specified space object.

To Delete a Space you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    ID string YesUnique identifier of the space to be deleted
pubnubObjects.DeleteSpace().ID(spaceid).Async((result, status) => {
        if (!status.Error) {
           //PNDeleteSpaceResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }

});
The DeleteUser() operation returns a PNDeleteSpaceResult which returns an empty object.

Returns the paginated list of space objects, optionally including the space's custom data object.

To Get Spaces you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    Count booleanOptionalRequest TotalCount to be included in paginated response. Default false
    Include PNUserSpaceInclude[]OptionalList of additional/complex user attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes.
    LimitintOptionalMaximum number of results to return per page. Default 100.
    StartstringOptionalPreviously-returned cursor bookmark for fetching the next page.
    EndstringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
    FilterstringOptionalExpression 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).
pubnub.GetSpaces().Async((result, status) => {
        if (!status.Error) {
           //PNGetSpacesResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }
});
The GetSpaces() operation returns a PNSpaceResult which contains the following parameters:
Property NameTypeDescription
DataList<PNSpaceResult>Details of PNSpaceResult are here.
TotalCountintTotal count of objects without pagination.
NextstringCursor bookmark for fetching next page.
PrevstringCursor bookmark for fetching prev page.

Returns the specified space object, optionally including the space's custom data object.

To Get a Space you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    ID string YesThe ID of the space to retrieve.
    Include PNUserSpaceInclude[]OptionalSpecifies whether to include custom object/field in the response.
pubnub.GetSpace().ID("space-id").Async((result, status) => {
        if (!status.Error) {
           //PNSpaceResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }

});
The GetSpace() operation returns a PNSpaceResult. Details of type PNSpaceResult are here.

Get the specified user's space memberships.

To Get Memberships you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    UserID stringYesUnique identifier of the user whose memberships you wish to retrieve.
    IncludePNMembershipsInclude[]OptionalList of additional/complex user attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes.
    LimitintOptionalMaximum number of results to return per page. Default 100.
    StartstringOptionalPreviously-returned cursor bookmark for fetching the next page.
    EndstringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
    FilterstringOptionalExpression 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).
PNMembershipsInclude[] inclMem= new PNMembershipsInclude[]{PNMembershipsInclude.PNMembershipsCustom, PNMembershipsInclude.PNMembershipsSpace, PNMembershipsInclude.PNMembershipsSpaceCustom};		

pubnub.GetMemberships().UserID("user-1").Include(inclMem).Limit(100).Count(true).Async((result, status) => {
        if (!status.Error) {
           //PNMembershipsResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }

});
The GetMemberships() operation returns a PNMembershipsResult which contains the following parameters:
Property NameTypeDescription
DataList<PNMemberships>Details of PNMemberships are here.
TotalCountintTotal count of objects without pagination.
NextstringCursor bookmark for fetching next page.
PrevstringCursor bookmark for fetching prev page.
Property NameTypeDescription
IDstringThe User ID.
CustomDictionary<string, object>Dictionary object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported.
SpacePNSpaceResultDetails of PNSpaceResult are here.
CreatedstringCreate date.
UpdatedstringLast updated date.
ETagstringThe ETag.

Get the specified space’s member users.

To Get Members you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    SpaceID stringYesUnique identifier of the space whose members you wish to retrieve.
    IncludePNMembersInclude[]OptionalList of additional/complex user attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes.
    LimitintOptionalMaximum number of results to return per page. Default 100.
    StartstringOptionalPreviously-returned cursor bookmark for fetching the next page.
    EndstringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
    FilterstringOptionalExpression 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).
PNMembersInclude[] inclSm = new PNMembersInclude[]{PNMembersInclude.PNMembersCustom, PNMembersInclude.PNMembersUser, PNMembersInclude.PNMembersUserCustom};		

pubnub.GetMembers().SpaceID("space-1").Include(inclSm).Limit(100).Count(true).Async((result, status) => {
        if (!status.Error) {
           //PNMembersResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }

});
The GetMembers() operation returns a PNMembersResult which contains the following parameters:
Property NameTypeDescription
DataList<PNMembers>Details of PNMembers are here.
TotalCountintTotal count of objects without pagination.
NextstringCursor bookmark for fetching next page.
PrevstringCursor bookmark for fetching prev page.
Property NameTypeDescription
IDstringThe Space ID.
CustomDictionary<string, object>Dictionary object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported.
UserPNSpaceResultDetails of PNUserResult are here.
CreatedstringCreate date.
UpdatedstringLast updated date.
ETagstringThe ETag.

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

To Manage Memberships you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    UserIDstringYesUnique identifier of the user whose memberships you wish to manage.
    AddList<PNMembersInput>OptionalList of type PNMembersInput to be added for the specified user. In PNMembersInput you can set the SpaceID and a Custom map.
    UpdateList<PNMembersInput>OptionalList of type PNMembersInput to be added for the specified user. In PNMembersInput you can set the SpaceID and a Custom map.
    RemoveList<PNMembersRemove>OptionalStruct of type PNMembersRemove to be removed for the specified user. In PNMembersRemove you can set the SpaceID
    LimitintOptionalMaximum number of results to return per page. Default 100.
    CountboolOptionalRequest TotalCount to be included in paginated response. Default false
    StartstringOptionalPreviously-returned cursor bookmark for fetching the next page.
    EndstringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
    IncludePNMembershipsInclude[]OptionalList of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes.
    Available values: PNMembershipsInclude.PNMembershipsCustom, PNMembershipsInclude.PNMembershipsSpace, PNMembershipsInclude.PNMembershipsSpaceCustom
PNMembershipsInclude[] inclMem= new PNMembershipsInclude[]{PNMembershipsInclude.PNMembershipsCustom, PNMembershipsInclude.PNMembershipsSpace, PNMembershipsInclude.PNMembershipsSpaceCustom};		
PNMembersInput input = new PNMembersInput();
input.ID = "add-space-id";
Dictionary<string, object> membershipCustom= new Dictionary<string, object>();
membershipCustom.Add("mememberscustomkey1", "memcv1");
membershipCustom.Add("mememberscustomkey2", "memcv2");
input.Custom = membershipCustom;

pubnub.ManageMemberships().UserID("user-1").Add(new List<PNMembersInput>{input}).Update(new List<PNMembersInput>{}).Remove(new List<PNMembersInput>{}).Include(inclMem).Limit(100).Count(true).Async((result, status) => {
        if (!status.Error) {
           //PNMembershipsResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }
});
The ManageMemberships() operation returns a PNMembershipsResult. Details of type PNMembershipsResult are here.

Manage the specified space’s member users. You can Add, Remove, and Update a space's members.

To Manage Members you can use the following method(s) in the Unity V4 SDK:
  1. ParameterTypeRequiredDescription
    SpaceIDstringYesUnique identifier of the space whose members you wish to manage.
    AddList<PNMembersInput>OptionalList of type PNMembersInput to be added for the specified user. In PNMembersInput you can set the UserID and a Custom map.
    UpdateList<PNMembersInput>OptionalList of type PNMembersInput to be added for the specified user. In PNMembersInput you can set the UserID and a Custom map.
    RemoveList<PNMembersRemove>OptionalStruct of type PNMembersRemove to be removed for the specified user. In PNMembersRemove you can set the UserID
    LimitintOptionalMaximum number of results to return per page. Default 100.
    CountboolOptionalRequest TotalCount to be included in paginated response. Default false
    StartstringOptionalPreviously-returned cursor bookmark for fetching the next page.
    EndstringOptionalPreviously-returned cursor bookmark for fetching the previous page. Ignored if you also supply the start parameter.
    IncludePNMembersInclude[]OptionalList of additional/complex attributes to include in response. Omit this parameter if you don't want to retrieve additional attributes.
    Available values: PNMembersInclude.PNMembersCustom, PNMembersInclude.PNMembersUser, PNMembersInclude.PNMembersUserCustom
PNMembersInclude[] inclSm = new PNMembersInclude[]{PNMembersInclude.PNMembersCustom, PNMembersInclude.PNMembersUser, PNMembersInclude.PNMembersUserCustom};		
PNMembersInput input = new PNMembersInput();
input.ID = "add-id-test";
Dictionary<string, object> membersCustom = new Dictionary<string, object>();
membersCustom.Add("memberscustomkey1", "mcv1");
membersCustom.Add("memberscustomkey2", "mcv2");
input.Custom = membersCustom;

pubnub.ManageMembers().SpaceID("space-1").Add(new List<PNMembersInput>{input}).Update(new List<PNMembersInput>{}).Remove(new List<PNMembersRemove>{}).Include(inclSm).Limit(100).Count(true).Async((result, status) => {
        if (!status.Error) {
           //PNMembersResult
        } else {
            Debug.Log(status.Error);
            Debug.Log(status.ErrorData.Info);
        }
});
The ManageMembers() operation returns a PNMembersResult. Details of type PNMembersResult are here.

The filtering language for Objects is similar to the stream filtering language.

Note the following:

  • Date/time properties, such as updated, must be compared to valid date/time strings formatted according to ISO 8601.
  • Custom properties must have the same type as the value used in the expression; it is an error to compare a custom property of one type to a value of another type.
  • Objects that do not have the referenced custom property at all are excluded regardless of the operator or value used in the expression. The null value can be used to filter out objects that do or do not have the referenced custom property.
  • The LIKE operator supports wildcards denoted by the * character. A wildcard matches any sequence of arbitrary Unicode characters, including the empty sequence. The literal asterisk is matched when escaped using the backslash (\) character.
  • Values used with LIKE must be properly encoded just like any other string value. Thus, in order to escape an asterisk, the raw value must contain \\*.
  • The entire expression must be properly URL-encoded when used in the query string.

<expression>           ::= <and_expression> ( "||" <and_expression> )*
<and_expression>       ::= <binary_condition> ( "&&" <binary_condition> )*
<binary_condition>     ::= "!" <binary_condition> | "(" <expression> ")" | <relational_condition>
<relational_condition> ::= <property_path> <relational_operator> <value>
<property_path>        ::= <property_name> ( "." <property_name> )*
<property_name>        ::= <identifier> | "[" <string> "]"
<value>                ::= <string> | <number> | "true" | "false" | "null"

Tokens

<identifier>           ::=  <letter> | "$" | "_" ( <letter> | "$" | "_" | <digit> )*
<relational_operator>  ::= "==" | "!=" | "<=" | ">=" | "<" | ">" | "LIKE"
<string>               ::= <double_quote> ( "\" <double_quote> | "\" <special_char>
                            | "\" "u" <hex_digit> <hex_digit> <hex_digit> <hex_digit>
                            | <unicode_char> - <double_quote> - "\" )* <double_quote>
                            | "'" ( "\" "'" | "\" <special_char>
                            | "\" "u" <hex_digit> <hex_digit> <hex_digit> <hex_digit>
                            | <unicode_char> - "'" - "\" )* "'"
<number>               ::= ( "+" | "-" )? ( <digit> )* ( "." )? <digit> ( <digit> )* 
                            ( "e" | "E" ( "+" | "-" )? <digit> ( <digit> )* )?
<letter>               ::= Unicode Letter (category; any kind of letter from any language)
<digit>                ::= "0" .. "9"
<hex_digit>            ::= <digit> | "A" .. "F"
<double_quote>         ::= the " character
<unicode_char>         ::= any character in the Unicode range from U+0020 to U+10FFFF inclusive
<special_char>         ::= "\" | "/" | "b" | "f" | "n" | "r" | "t"

The following simple expression returns results whose custom property named public is equal to Boolean true.


custom.public == true

The following date/time comparison returns results that were modified on or after August 31st, 2019 (UTC):


updated >= "2019-08-31T00:00:00Z"

The following compound expression returns results that don't have a description, but do have a non-empty custom label or description property:


description == null && (custom.label != "" || custom.description != "")

The following wildcard expression returns results whose name starts with the letter X:


name LIKE 'X*'

The following escaped wildcard expression returns results whose name contains an asterisk:


name LIKE '*\\**'