vb.net add user and assign groups to the user

Aug 10, 2011 at 9:33 PM

I have seen some of the other examples out here in different programming languages, but am having an issue translating the code to add groupins for a given user in vb.net.

Basically, I am pulling in people from active directory and am doing a ListBatchSubscribe.  I have all my code working to get users added in via the api.  The next piece I am struggling to translate form the other examples is how to take a users departments and roles and set them as that individuals interests.  I am including the simplified version of my code as all of the looping through active directory and database stuff is not relevant to my true need, which is how do I get groupings set for a user with vb.net.

Basically for the "user" below I want to assign two different interests. For the individual I want them in the Group Title of "IT" and the Group Name of "Programmer" and the Group Title of "Marketing" and the Group Name of "General"

Here is the simplified code.  Any help would be much appreciated.  I was attempting to go down the path of Member.Groupings, but didn't make it any further than that.

        Dim Member As MailChimp.Types.List.Merges
        Dim BatchSubscribe As MailChimp.Types.List.BatchSubscribe
        Dim SubscribeOptions As New MailChimp.Types.List.SubscribeOptions()
        Dim SubscribeList(100000) As MailChimp.Types.List.Merges
        Dim SubscribeCount As Int64 = 0

        Member = New MailChimp.Types.List.Merges
        Member.Add("EMAIL", "email@test.com"
        Member.Add("FNAME", "Test")
        Member.Add("LNAME", "Testing")

        SubscribeList(SubscribeCount) = Member
        SubscribeCount = SubscribeCount + 1
        SubscribeOptions.DoubleOptIn = False
        SubscribeOptions.EmailType = MailChimp.Types.List.EmailType.Html
        SubscribeOptions.SendWelcome = False
        SubscribeOptions.ReplaceInterests = True
        SubscribeOptions.UpdateExisting = True

        ReDim Preserve SubscribeList(SubscribeCount - 1)

        BatchSubscribe = _APIMC.ListBatchSubscribe(My.Settings.MailChimpListID, SubscribeList, SubscribeOptions)

Aug 11, 2011 at 10:54 PM
Edited Aug 11, 2011 at 10:54 PM

Try Campign.Grouping class. Add it to merges.

Aug 12, 2011 at 1:43 AM

But as far as I can tell there is no Campaign.Grouping class.  Do you mean List.Grouping?  The problem is that I am not seeing how to populate the items into List.Grouping.

Aug 12, 2011 at 7:54 AM

Look at the initializer of merges. U have 2 options:

- new Merges(email, emailType)

- new Merges(email, emailType, groupings), where groupings is a sequence (array, list etc) of Groupings type.


Feb 23, 2013 at 4:48 PM
I spent an embarassing about of time getting groups to work with VB.NET, didn't find a single good example, so thought I'd share.

In the following example, in MailChimp, I have a groups setup like this:


The code below adds the email address to a total of 3 groups.

ListUpdateMember should take the Groupings in the same manner.

Hope this example helps someone!
    Dim api As New MailChimp.MCApi("YourAPIKey", True)

    Dim Data As MailChimp.Types.MCList(Of MailChimp.Types.List.ListsDataItem)
    Dim Lis As New MailChimp.Types.List.Lists(0, Data)
    Lis = api.Lists()
    Dim ListID As String
    ListID = Lis.Data.Item(0).ListID

    Dim Mer As New MailChimp.Types.List.Merges
    Mer.Item("FNAME") = "Sally"
    Mer.Item("LNAME") = "Smith"

    Dim ea As New Types.MCList(Of Types.List.Grouping)
    Dim e1 As New Types.List.Grouping("Group1", {"Group1a","Group1b"})
    Dim e2 As New Types.List.Grouping("Group2", {"Group2a"})

    Dim SubscribeOptions As New Types.List.SubscribeOptions
    SubscribeOptions.DoubleOptIn = False
    SubscribeOptions.ReplaceInterests = True
    SubscribeOptions.UpdateExisting = True

    Mer.Item("Groupings") = ea

    api.ListSubscribe(ListID, "email@domain12345.com", Mer, SubscribeOptions)