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.

create a contact list

Highlighted
New Member

create a contact list

I am completely new to both constant contact and .NET. i have a registration form where users can register themselves. what i want is that at the end of registration the details i.e id, first name and last name of the users should get stored in the contact list. I m using c#. can anyone please provide me wth step by step process to do the above task. 

 

thanks a lot..

5 REPLIES 5
Highlighted
Honored Contributor

Re: create a contact list

Hello,

 

When you are working with Constant Contact, we provide an API that enables the ability to access our accounts from outside of our systems. An example of what you can do is exactly what you have described where you can integrate a signup form with Constant Contact.

 

In order to get started, you will need to get set up with an API key so that you can make use of our tools for C#. I would suggest visiting the Getting Started guide on our Developer Homepage. Once you are set up with an API key and access token, you will want to look into the code samples and API wrapper library for C#.

 

In the samples that are provided with the C# library, one of them is specifically showing how to add contacts to Constant Contact using information from a signup form. In addition, there is also a sample demonstrating how to create and send emails from Constant Contact.

 

While these resources are likely enough to get started with, pleae feel free to reply to this thread if you get stuck and need some answers/assistance!

 

Sincerely,

Elijah G.

API Support Specialist

Elijah G.
API Support Engineer
Highlighted
Regular Visitor

Re: create a contact list

sir, i have acquired the key and token. I have also downloaded the constant-contact-dot-net-wrapper. Please let me know how to add references to my project. and also I dont see any sample code that mathches to my problem. Please provide me a link to the sample code.

 

thanks a lot...

Highlighted
Moderator

Re: create a contact list

If you are looking to use our most updated API version and wrapper library (our v2 JSON API), you would want to use the .net-sdk project found here: https://github.com/constantcontact/.net-sdk

 

This project has samples for how to make requests, a full wrapper library for all of our v2 endpoints and a very simple way to use OAuth 2.0 access tokens to access your data.  Hope this helps!

Dave Berard
Senior Product Manager, Constant Contact
Highlighted
Regular Visitor

Re: create a contact list

sir, I hv used the api but it is nt adding contacts in my list.

 

private AuthenticationData AuthenticationData
{
get
{
if (Session["AuthenticationData"] == null)
{
Session.Add("AuthenticationData", ConstantContact.AuthenticationData);
}
return (AuthenticationData)Session["AuthenticationData"];
}
}

 

 

protected void dvStudent_PageIndexChanging(object sender, DetailsViewPageEventArgs e)  

// this is my button for registration
{
TextBox textEmail = dvStudent.FindControl("textEmail") as TextBox;

string[] emailAddress = new string[] { textEmail.Text.Trim() };
try
{
string nextChunkId;
IList<Contact> list = Utility.SearchContactByEmail(AuthenticationData, emailAddress, out nextChunkId);
if (list.Count == 0)
{
// create new Contact
Contact contact = GetContactInformation();

Utility.CreateNewContact(AuthenticationData, contact);
//Response.Redirect("~/AddContactConfirmation.aspx");

ContactOptInList contactOptInList = new ContactOptInList();
contactOptInList.ContactList = new ContactList("1");
contact.ContactLists.Add(contactOptInList);
}
else
{
throw new ConstantException(String.Format(CultureInfo.CurrentCulture,
"Email address \"{0}\" is already a contact", textEmail.Text.Trim()));


}
}
catch (ConstantException ce)
{
#region display alert message
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append(@"<script language='javascript'>");
stringBuilder.AppendFormat(@"alert('{0}')", ce.Message);
stringBuilder.Append(@"</script>");
ClientScript.RegisterStartupScript(typeof(Page), "AlertMessage", stringBuilder.ToString());
#endregion
}


}

private Contact GetContactInformation()
{
Contact contact = new Contact();

#region contact information

TextBox textEmail = dvStudent.FindControl("textEmail") as TextBox;
contact.EmailAddress = Server.HtmlEncode(textEmail.Text.Trim());

TextBox textFirstName = dvStudent.FindControl("textFirstName") as TextBox;
contact.FirstName = Server.HtmlEncode(textFirstName.Text.Trim());

TextBox textMiddleName = dvStudent.FindControl("textMiddleName") as TextBox;
contact.MiddleName = Server.HtmlEncode(textMiddleName.Text.Trim());

TextBox textLastName = dvStudent.FindControl("textLastName") as TextBox;
contact.LastName = Server.HtmlEncode(textLastName.Text.Trim());

TextBox textDayPhoneNumber = dvStudent.FindControl("textDayPhoneNumber") as TextBox;
contact.HomePhone = Server.HtmlEncode(textDayPhoneNumber.Text.Trim());

TextBox textAddress = dvStudent.FindControl("textAddress") as TextBox;
contact.AddressLine1 = Server.HtmlEncode(textAddress.Text.Trim());

TextBox textAddress2 = dvStudent.FindControl("textAddress2") as TextBox;
contact.AddressLine2 = Server.HtmlEncode(textAddress2.Text.Trim());

TextBox textAddress3 = dvStudent.FindControl("textAddress3") as TextBox;
contact.AddressLine3 = Server.HtmlEncode(textAddress3.Text.Trim());

TextBox textCity = dvStudent.FindControl("textCity") as TextBox;
contact.City = Server.HtmlEncode(textCity.Text.Trim());
TextBox textPostalCode = dvStudent.FindControl("textPostalCode") as TextBox;

contact.PostalCode = Server.HtmlEncode(textPostalCode.Text.Trim());
#endregion

return contact;
}

 

can you plz let me knw where is the error in this code.

 

also the changes dat i hv made in my web.cong file are:

 

<add key="APIKey" value=""/>

<add key="RedirectURL" value="http://www.constantcontact.com/index.jsp"/>
<add key="Password" value=""/>
<add key="Username" value=""/>

 

Thanks a lot...

Highlighted
Moderator

Re: create a contact list

It looks like the way you have coded this, it shouldn't add the Contact to a list.  If you look at this portion of your code:

 

Contact contact = GetContactInformation();

Utility.CreateNewContact(AuthenticationData, contact);

ContactOptInList contactOptInList = new ContactOptInList();

contactOptInList.ContactList = new ContactList("1");
contact.ContactLists.Add(contactOptInList);

 

You are creating the Contact before you are adding a list to the Contact.  If you change the order of this to the following, this should correctly add the Contact to the list you want:

 

Contact contact = GetContactInformation();

ContactOptInList contactOptInList = new ContactOptInList();

contactOptInList.ContactList = new ContactList("1");

contact.ContactLists.Add(contactOptInList);

Utility.CreateNewContact(AuthenticationData, contact);

 

When you use the method CreateNewContact(), this will send us the exact settings of the contact object you're passing and create the Contact with that information (or fail if there is an error condition).  You need to make sure you add all of the correct attributes to the Contact object before passing it that you want the Contact to have. 

 

Given you are not setting any lists when you are sending your create request, I would expect your code to through a ConstantException that you should catch.  The InnerException of that should be a WebException that has a StatusCode of 400 since you didn't provide at least one ContactList which is required to create the Contact. 

 

Hope this helps!

Dave Berard
Senior Product Manager, Constant Contact
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