The Community is hosting an End of Summer sweepstakes! Participants must complete tasks to earn tickets that will enter them with a chance to win a free year of Constant Contact and other great prizes!*
*No Purchase Necessary. For Official Rules, visit here. Constant Contact’s End of Summer 2020 Sweepstakes ends on October, 20, 2020 at 11:50 PM EST.

Need help adding a Contact through the C# api wrapper

Highlighted

Need help adding a Contact through the C# api wrapper

I am trying to integrate Constant Contact into our application. My goal is to automatically add the contact to the client's Constant Contact account when they add a contact in our application. Eventually we will add more but this is step 1.

 

I have downloaded the C# wrapper and successfully ran it using my Auth Data. I am having trouble adding a contact as it wants the list to add the contact to. I am wanting to add the contact to the accounts default list or pull back all of the contact lists and display them as check boxes in my application so my clients can choose which lists to add a new contact to.

 

1.  At this point I am getting an error trying to add a contact because no list is specified. How do I specify the default list?

2. I do not see any methods in the api wrapper to pull back the list collection. Is this not available?

 

Thanks for any ideas/help!

 

Dog Biz Pro

1 REPLY 1
Highlighted
Employee

Re: Need help adding a Contact through the C# api wrapper

Hey Stephanie,

 

You would create a contact like this:

 

                myAuth.Username = "username";
                myAuth.Password = "password";
                myAuth.ApiKey = "apikey";
                                
                Contact theContact = new Contact();
                theContact.EmailAddress = emailAddressText.Text;

                ContactOptInList theList = new ContactOptInList();
                theContact.OptInSource = ContactOptSource.ActionByContact;
                theList.ContactList = new ContactList("1");

                theContact.ContactLists.Add(theList);
                               

                ConstantContactUtility.Utility.CreateNewContact(myAuth, theContact);

 As far as getting the entire list collection, this would be how:

 

private void login_btn_Click(object sender, EventArgs e)
        {

            authdata = new AuthenticationData();
            authdata.Username = username_txt.Text;
            authdata.Password = password_txt.Text;
            authdata.ApiKey = "APIKEY";  // Insert your API key
            String nextChunkId, currentChunkId = null;
            List<ContactList> ContactLists = new List<ContactList>();


            // Takes all contact lists
            try
            {
                do
                {
                    ContactLists.AddRange((List<ContactList>)Utility.GetUserContactListCollection(authdata, currentChunkId, out nextChunkId));
                    currentChunkId = nextChunkId;


                } while (nextChunkId != "");

                StringBuilder s = new StringBuilder();
                foreach (ContactList n in ContactLists)
                {
                    s.AppendLine(n.Name);
                }

                displayLists_txt.Text = s.ToString();
            }

            catch (Exception ex)
            {
                errorHandler_lbl.Text = "please try logging in again";
            }
            

           
            
        }

 

Let me know if that helps.

Ryan Davis
Quality Engineer
Developer Portal

View API documentation, code samples, get your API key.

Visit Page

Constant Contact 2020 End of Summer Community Sweepstakes!

The Constant Contact User Community is hosting a sweepstakes. The more you participate, the more chances you have to win! Read on to learn more...

Read More
Featured