Programatically creating contact groups?

studlyed
Posts: 12
Joined: Sat Apr 04, 2009 7:17 am

Programatically creating contact groups?

Postby studlyed » Sat Apr 04, 2009 7:24 am

Hey all,
I see in the API that we can create contacts, which works great. But how do I create a group of contacts? I can't find anything referencing groups of contacts except for a bool value when getting a list of contacts through AJAX. Which for some weird reason, I have to do an AJAX login call on a freshly created account to be able to add contacts.

Thanks in advance,
Ed

studlyed
Posts: 12
Joined: Sat Apr 04, 2009 7:17 am

Postby studlyed » Tue Apr 21, 2009 2:19 am

I found a way to do it. It's not documented, infact, there's a lot not documented with the API and .net. Took a while to figure it out, but, hopefully this will help someone.

Code: Select all

                                MailEnable.MailboxContact.ContactGroup group = new MailEnable.MailboxContact.ContactGroup();
                                MailEnable.MailboxContact.ContactGroups groups = new MailEnable.MailboxContact.ContactGroups();
                                string newName = groupName.Replace("'", "");
                                groups.Postoffice = "postoffice";
                                groups.UserName = "mailbox";
                                group = groups.AddGroup(newName);
                                //these next few lines are because if you dont do this, it will overwrite the currently existing groups...weird
                                group = new MailEnable.MailboxContact.ContactGroup();
                                group.Postoffice = _mailBox.Postoffice;
                                group.UserName = _mailBox.MailboxName;
                                group.GroupName = newName;
                                bool myResult = group.FetchByName();
                                if (!myResult) { Console.WriteLine("Unable to create and load group."); }


And to add a contact to the group....

Code: Select all

int result = group.AddMember(storeItem.StoreItem_GetProperty("ME_ITEM_ID", string.Empty));
if (result != 0) { Console.WriteLine("Unable to add."); }
bool outter = groups.UpdateGroup(group.ListID, group.GroupName, group.GetMemberAddressIDList());
if (!outter) { Console.WriteLine("Unable to save group."); }

I don't know if the groups.UpdateGroup line is required, but it works for me.[/quote]

Who is online

Users browsing this forum: No registered users and 2 guests