C#C# V4 Objects (BETA) API Reference for Realtime Apps

 

These docs are for PubNub 4.0 for C# which is our latest and greatest! For the docs of the 3.x versions of the SDK, please check the links: C#, Windows 8, Windows 8.1, ASP.Net, Windows Phone 8, Windows Phone 8.1, Xamarin.iOS, Xamarin.Android, Xamarin.Mac and C# PCL.

If you have questions about the PubNub for C# 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 C# 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.
    CustomObjectDictionary<string, object>OptionalDictionary object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported.
pubnub.CreateUser()
    .Id("user-1")
    .Name("John Doe")
    .Email("jack@twitter.com")
    .Execute(new PNCreateUserResultExt(
        (result, status) => {
            //result is of type PNCreateUserResult.
        }
    ));
The CreateUser() operation returns a PNCreateUserResult which contains the following parameter:
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.

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 C# 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.
    CustomObjectDictionary<string, object>OptionalDictionary object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported.
Dictionary<string, object> myUpdCust = new Dictionary<string, object>();
myUpdCust.Add("color", "red-update");
pubnub.UpdateUser()
    .Id("user-1")
    .Name("John Doe Update")
    .CustomObject(myUpdcust)
    .Execute(new PNUpdateUserResultExt(
        (result, status) => {
            //result is of type PNUpdateUserResult.
        }
    ));
The UpdateUser() operation returns a PNUpdateUserResult which contains the following parameter:
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.

Deletes the specified user object.

To Delete a User you can use the following method(s) in the C# V4 SDK:
  1. ParameterTypeRequiredDescription
    IdstringYesID of the user to delete.
pubnub.DeleteUser()
    .Id("user-1")
    .Execute(new PNDeleteUserResultExt(
        (result, status) => {
            //result is of type PNDeleteUserResult.
        }
    ));
The DeleteUser() operation returns a PNDeleteUserResult which returns 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 C# V4 SDK:
  1. ParameterTypeRequiredDescription
    IncludeCount booleanOptionalSpecifies whether to include total result count.
    IncludeCustom booleanOptionalSpecifies whether to include custom object/field in the response.
    LimitintOptionalMaximum number of results to return per page
    PageobjectOptional

    To get the next set of results, specify next.
    To get the previous set of results, specify prev.
    If you specify both, prev is ignored.

pubnub.GetUsers()
    .IncludeCount(true)
    .IncludeCustom(true)
    .Limit(2)
    .Page(new PNPage() {
        Next = "",
        Prev = ""
    })
    .Execute(new PNGetUsersResultExt(
        (result, status) => {
            //result is of type PNGetUsersResult.
        }
    ));
The GetUsers() operation returns a PNGetUsersResult which contains the following parameter:
Property NameTypeDescription
UsersList<PNUserResult>Details of PNUserResult are here.
TotalCountintTotal count of user objects.
PagePNPageDetails of PNPage are here.
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.
Property NameTypeDescription
NextstringNext set of results.
PrevstringPrevious set of results.

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 C# V4 SDK:
  1. ParameterTypeRequiredDescription
    UserIdstringYesThe ID of the user to retrieve.
    IncludeCustom booleanOptionalSpecifies whether to include custom object/field in the response.
pubnub.GetUser()
    .UserId("user-1")
    .IncludeCustom(true)
    .Execute(new PNGetUserResultExt(
        (result, status) => {
            //result is of type PNGetUserResult.
        }
    ));
The GetUser() operation returns a PNGetUserResult which contains the following parameter:
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

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 C# V4 SDK:
  1. ParameterTypeRequiredDescription
    Id stringYesUnique identifier of the space.
    Name stringYesDisplay name of the space.
    Description stringOptionalDescription of the space.
    CustomObjectDictionary<string, object>OptionalDictionary object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported.
pubnub.CreateSpace()
    .Id("space-id")
    .Name("space-name")
    .Description("space-description")
    .Execute(new PNCreateSpaceResultExt(
        (result, status) => {
            //result is of type PNCreateSpaceResult.
        }
    ));
The CreateSpace() operation returns a PNCreateSpaceResult which contains the following parameter:
Property NameTypeDescription
IdstringThe user ID.
NamestringDisplay name for the user.
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.
CreatedstringCreate date.
UpdatedstringLast updated date.

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 C# 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.
    CustomObjectDictionary<string, object>OptionalDictionary object of key-value pairs with supported data types. Values must be scalar only; arrays or objects are not supported.
Dictionary<string, object> mySpaceUpdCust = new Dictionary<string, object>();
mySpaceUpdCust.Add("color", "red-update");
pubnub.UpdateSpace()
    .Id("space-id")
    .Name("space-name-update")
    .Description("space-description-update")
    .CustomObject(mySpaceUpdCust)
    .Execute(new PNUpdateSpaceResultExt(
        (result, status) => {
            //result is of type PNUpdateSpaceResult.
        }
    ));
The UpdateSpace() operation returns a PNUpdateSpaceResult which contains the following parameter:
Property NameTypeDescription
IdstringThe user ID.
NamestringDisplay name for the user.
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.
CreatedstringCreate date.
UpdatedstringLast updated date

Deletes the specified space object.

To Delete a Space you can use the following method(s) in the C# V4 SDK:
  1. ParameterTypeRequiredDescription
    Id string YesUnique identifier of the space to be deleted
pubnub.DeleteSpace()
    .Id("space-id")
    .Execute(new PNDeleteSpaceResultExt(
        (result, status) => {
            //result is of type PNDeleteSpaceResult.
        }
    ));
The DeleteSpace() operation returns a PNDeleteSpaceResult which returns 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 C# V4 SDK:
  1. ParameterTypeRequiredDescription
    IncludeCount booleanOptionalSpecifies whether to include total result count.
    IncludeCustom booleanOptionalSpecifies whether to include custom object/field in the response.
    Limit intOptionalMaximum number of results to return per page
    PageobjectOptional

    To get the next set of results, specify next.
    To get the previous set of results, specify prev.
    If you specify both, prev is ignored.

pubnub.GetSpaces()
    .IncludeCount(true)
    .IncludeCustom(true)
    .Limit(2)
    .Page(new PNPage() {
        Next = "",
        Prev = ""
    })
    .Execute(new PNGetSpacesResultExt(
        (result, status) => {
            //result is of type PNGetSpacesResult.
        }
    ));
The GetSpaces() operation returns a PNGetSpacesResult which contains the following parameter:
Property NameTypeDescription
SpacesList<PNSpaceResult>Details of PNSpaceResult are here.
TotalCountintTotal count of space objects.
PagePNPageDetails of PNPage are here.
Property NameTypeDescription
IdstringThe user ID.
NamestringDisplay name for the user.
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.
CreatedstringCreate date.
UpdatedstringLast updated date.
Property NameTypeDescription
NextstringNext set of results.
PrevstringPrevious set of results.

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 C# V4 SDK:
  1. ParameterTypeRequiredDescription
    SpaceId string YesThe ID of the space to retrieve
    IncludeCustom booleanOptionalSpecifies whether to include custom object/field in the response.
pubnub.GetSpace()
    .SpaceId("space-id")
    .IncludeCustom(true)
    .Execute(new PNGetSpaceResultExt(
        (result, status) => {
            //result is of type PNGetSpaceResult.
        }
    ));
The GetSpace() operation returns a PNGetSpaceResult which contains the following parameter:
Property NameTypeDescription
IdstringThe user ID.
NamestringDisplay name for the user.
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.
CreatedstringCreate date.
UpdatedstringLast updated date.

Get the specified user's space memberships.

To Get Memberships you can use the following method(s) in the C# V4 SDK:
  1. ParameterTypeRequiredDescription
    UserId stringYesID of the user whose memberships you wish to retrieve
    Includeenum arrayOptionalSpecifies what custom object/field to include in the response.
    IncludeCount booleanOptionalSpecifies whether to include total result count.
    Limit intOptionalMaximum number of results to return per page
    PageobjectOptional

    To get the next set of results, specify next.
    To get the previous set of results, specify prev.
    If you specify both, prev is ignored.

pubnub.GetMemberships()
    .UserId("user-1")
    .Include(new PNMembershipField[] {
        PNMembershipField.CUSTOM,
        PNMembershipField.SPACE,
        PNMembershipField.SPACE_CUSTOM
    })
    .IncludeCount(true)
    .Limit(2)
    .Page(new PNPage() {
        Next = "",
        Prev = ""
    })
    .Execute(new PNGetMembershipsResultExt(
        (result, status) => {
            //result is of type PNGetMembershipsResult.
        }
    ));
The GetMemberships() operation returns a PNGetMembershipsResult which contains the following parameter:
Property NameTypeDescription
MembershipsList<PNMembershipsItemResult>Details of PNMembershipsItemResult are here.
TotalCountintTotal count of objects.
PagePNPageDetails of PNPage are here.
Property NameTypeDescription
SpaceIdstringThe 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.
SpacePNSpaceResultDetails of PNSpaceResult are here.
CreatedstringCreate date.
UpdatedstringLast updated date.
Property NameTypeDescription
IdstringThe user ID.
NamestringDisplay name for the user.
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.
CreatedstringCreate date.
UpdatedstringLast updated date.
Property NameTypeDescription
NextstringNext set of results.
PrevstringPrevious set of results.

Get the specified space’s member users.

To Get Members you can use the following method(s) in the C# V4 SDK:
  1. ParameterTypeRequiredDescription
    SpaceId stringYesID of the space whose members you wish to retrieve.
    Includeenum arrayOptionalSpecifies what custom object/field to include in the response.
    IncludeCount booleanOptionalSpecifies whether to include total result count.
    Limit intOptionalMaximum number of results to return per page
    PageobjectOptional

    To get the next set of results, specify next.
    To get the previous set of results, specify prev.
    If you specify both, prev is ignored.

pubnub.GetMembers()
    .SpaceId("space-1")
    .Include(new PNMemberField[] {
        PNMemberField.CUSTOM,
        PNMemberField.USER,
        PNMemberField.USER_CUSTOM
    })
    .IncludeCount(true)
    .Limit(2)
    .Page(new PNPage() {
        Next = "",
        Prev = ""
    })
    .Execute(new PNGetMembersResultExt(
        (result, status) => {
            //result is of type PNGetMembersResult.
        }
    ));
The GetMembers() operation returns a PNGetMembersResult which contains the following parameter:
Property NameTypeDescription
MembersList<PNMembersItemResult>Details of PNMembersItemResult are here.
TotalCountintTotal count of objects.
PagePNPageDetails of PNPage are here.
Property NameTypeDescription
UserIdstringThe 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.
UserPNUserResultDetails of PNUserResult are here.
CreatedstringCreate date.
UpdatedstringLast updated date.
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.
Property NameTypeDescription
NextstringNext set of results.
PrevstringPrevious set of results.

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 C# V4 SDK:
  1. ParameterTypeRequiredDescription
    UserIdstringYesID of the user.
    AddlistOptionalList of PNMembership space memberships to be added for the specified user.
    UpdatelistOptionalList of PNMembership space memberships to be updated for the specified user.
    RemovelistOptionalThe IDs of spaces from which to remove the specified user.
    Includeenum arrayOptionalSpecifies what custom object/field to include in the response.
    IncludeCount booleanOptionalSpecifies whether to include total result count.
    LimitintOptionalRetrieve specific number of objects.
    PageobjectOptional

    To get the next set of results, specify next.
    To get the previous set of results, specify prev.
    If you specify both, prev is ignored.

List<PNMembership> addList = new List<PNMembership>();
addList.Add(new PNMembership() {
    SpaceId = "add-space-id"
});

List<PNMembership> updateList = new List<PNMembership>();
updateList.Add(new PNMembership() {
    SpaceId = "upd-space-id",
    Custom = new Dictionary<string, object>() {
        {
            "foo", "bar"

        }
    }
});

List<string> removeList = new List<string>();
removeList.Add("del-space-id");

pubnub.Memberships()
    .UserId("user-1")
    .Add(addList)
    .Update(updateList)
    .Remove(removeList)
    .Include(new PNMembershipField[] {
        PNMembershipField.CUSTOM,
        PNMembershipField.SPACE,
        PNMembershipField.SPACE_CUSTOM
    })
    .IncludeCount(true)
    .Limit(2)
    .Page(new PNPage() { 
        Next = "",
        Prev = "" 
    })
    .Execute(new PNMembershipsResultExt(
        (r, s) => {
            //result is of type PNMembershipsResult.
        }
    ));
The Memberships() operation returns a PNMembershipsResult which contains the following parameter:
Property NameTypeDescription
MembershipsList<PNMembershipsItemResult>Details of PNMembershipsItemResult are here.
TotalCountintTotal count of objects.
PagePNPageDetails of PNPage are here.
Property NameTypeDescription
SpaceIdstringThe 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.
SpacePNSpaceResultDetails of PNSpaceResult are here.
CreatedstringCreate date.
UpdatedstringLast updated date.
Property NameTypeDescription
IdstringThe user ID.
NamestringDisplay name for the user.
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.
CreatedstringCreate date.
UpdatedstringLast updated date.
Property NameTypeDescription
NextstringNext set of results.
PrevstringPrevious set of results.

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 C# V4 SDK:
  1. ParameterTypeRequiredDescription
    SpaceIdstringYesID of the space.
    AddListOptionalList of PNMember records containing the users to be added for the specified space.
    UpdateListOptionalList of PNMember records containing the users to be updated for the specified space.
    RemoveListOptionalThe IDs of users to be removed from the specified space.
    Includeenum arrayOptionalSpecifies what custom object/field to include in the response.
    IncludeCount booleanOptionalSpecifies whether to include total result count.
    LimitintOptionalRetrieve a specific number of objects.
    PageobjectOptional

    To get the next set of results, specify next.
    To get the previous set of results, specify prev.
    If you specify both, prev is ignored.

List<PNMember> addMemberList = new List<PNMember>();
addMemberList.Add(new PNMember() {
    UserId = "add-id-test"
});

List<PNMember> updMemberList = new List<PNMember>();
updMemberList.Add(new PNMember() {
    UserId = "upd-id-test",
    Custom = new Dictionary<string, object>() {
        {
            "foo-0",
            "bar-0"
        }
    }
});

List<string> remMemberList = new List<string>();
remMemberList.Add("del-id-test");

pubnub.Memberships()
    .UserId("user-1")
    .Add(addMemberList)
    .Update(updMemberList)
    .Remove(remMemberList)
    .Include(new PNMemberField[] {
        PNMemberField.CUSTOM,
        PNMemberField.USER,
        PNMemberField.USER_CUSTOM

    })
    .IncludeCount(true)
    .Limit(2)
    .Page(new PNPage() {
        Next = "",
        Prev = ""
    })
    .Execute(new PNMembersResultExt(
        (r, s) => {
            //result is of type PNMembersResult.
        }
    ));
The Members() operation returns a PNMembersResult which contains the following parameter:
Property NameTypeDescription
MembersList<PNMembersItemResult>Details of PNMembersItemResult are here.
TotalCountintTotal count of objects.
PagePNPageDetails of PNPage are here.
Property NameTypeDescription
UserIdstringThe 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.
UserPNUserResultDetails of PNUserResult are here.
CreatedstringCreate date.
UpdatedstringLast updated date.
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.
Property NameTypeDescription
NextstringNext set of results.
PrevstringPrevious set of results.