Disclosure: Your support helps keep the site running! We earn a referral fee for some of the services we recommend on this page. Learn more

Hacks for Creating Dynamic Content

Inserting Contacts and Variables

Contact PropertyVariable Name in Email CampaignImport File Column Name
Email address$SUBSCRIBER.EMAILEmail address - work 
Or, Email address - home
First name$SUBSCRIBER.FIRSTNAMEFirst name
Last name$SUBSCRIBER.LASTNAMELast name
Mailing address line 1$SUBSCRIBER.ADDRESSLINE1Address line 1
Mailing address line 2$SUBSCRIBER.ADDRESSLINE2Address line 2
Mailing address line 3$SUBSCRIBER.ADDRESSLINE3Address line 3
Mailing address city$SUBSCRIBER.CITYCity
State name$SUBSCRIBER.STATENAMEState
Postal (zip) code$SUBSCRIBER.POSTCODEZip/Postal Code
Home phone number$SUBSCRIBER.HOMEPHONENUMBERPhone number - Home
Job title$SUBSCRIBER.JOBTITLEJob Title
Custom field n (n=1-15)$SUBSCRIBER.CUSTOMTEXTnCustom field n

Please note: When using the normal email editor (instead of the custom code option) head to the “Contact Details” section to merge this dynamic content into your campaign. The above instructions won’t work for the online templates as these work differently.

Inserting Contact Fields

If the above table doesn’t allow you to pull the data you want, try the custom field property, which enables you to store unique information about each of your contacts. Custom fields can be created ahead of time or while you’re updating/adding your contacts from a file.

Custom Field Limits

      • 50 characters max in the API. To put together longer content, use multiple custom fields.
      • 15 custom fields (max) can be used.
      • If you’re using a bulk method to import or using individual contact API endpoints, then specific custom field names must be used for the API: Use the format “Custom Field n” where n = 1-15.

An example Contact Import file is:

Email Address - HomeFirst NameCustom Field 1Custom Field 2Custom Field 3
[email protected]DaveSoccerAmerican FootballSaturday, September 20th
[email protected]JohnBakingSushi MakingWednesday, January 15th
[email protected]SarahWelding 101Hobby ElectronicsMonday, December 5th

Inserting Custom Content into Your Campaign

In the above example, the first name, email address, and 3 custom fields are what’s going to be pulled into the recipient’s custom content. This is the HTML that’s entered into the “Advanced Editor” part of a custom code email campaign or the email_content field in the API.

To put your content in, you must choose the XHTML option (you’ll also be presented with a HTML option). And here’s what your content will look like:

Dear $SUBSCRIBER.FIRSTNAME,
Thank you for being a part of our $SUBSCRIBER.CUSTOMTEXT1 class!
We thought you'd also like this $SUBSCRIBER.CUSTOMTEXT2 class, offered next $SUBSCRIBER.CUSTOMTEXT3.
<a href="http://placeholder.com/classes?email=$SUBSCRIBER.EMAIL">Click here to Register!</a>
I hope to see you there!
Sincerely,
Your friends at Soccer United Co.

Tips for Adding Contacts Directly from Your Website or Application

This simple post URL allows you to add contacts into your Constant Contact account without the need to redirect your customer to the Constant Contact website to finish filling the form in.

The code below focuses on how you can construct the raw request and will require your website to make a HTTPS call to https://visitor2.constantcontact.com/api/signup.

Authentication

The “ca” value is unique to each Constant Contact account. To find what yours is, log into your account and go to Contacts, then Sign-Up Tools, and Embed Code. Simply copy the code provided, find the “ca” parameter, and paste the value into the URL for your sign-up form.

An example of the ca id in an embed code:

name= "ca" type= "hidden" value= "12345-678-910" data-id= "ca:input"

Contact Fields

NameRequired?Description
address_cityThe contact’s city.
address_countryThe contact’s country
address_postal_codeThe contact’s ZIP code
adress_stateThe contact’s state
anniversary_dayMust include anniversary_year and anniversary_month - accepts numbers 1 to 31
anniversary_month"Must include anniversary_year and anniversary_day - accepts numbers 1 to 12
"
anniversary_year"Must include anniversary_day and anniversary_month - accepts numbers 1900 + and numbers that go up to 10 years into the future
"
birthday_dayMust include birthday_month - accepts numbers 1 to 31
birthday_monthAccepts numbers 1 to 12
caYesCampaign Activity ID (as explained above)
companycompany
emailYesThe contact’s email address
first_nameFirst name
job_titleJob title
last_nameLast name
List (or the variations lists, list_n)List IDs the contact’s going to be subscribed to. You can differentiate each list with “list_1” “list_2” and so on. If left blank, the contact will be automatically added to the list detailed in the sign-up form found in the product UI.
phonePhone number
urlURL the subscriber will be redirected to once they’ve submitted the form. If left blank, a 200 success response will be returned.

If the email address is already held in your account, their record will be updated. The contact will remain on all of the lists they’re already subscribed to.

Example URL

A URL that could be constructed to add a customer to a number of lists:

https://visitor2.constantcontact.com/api/signup?ca=xxxxx&amp;[email protected]&amp;first_name=Joe
&amp;list=xxxx&amp;list=xxxxx

Creating a Sign-up Form

This is an example of a sign-up form you can embed in your website. This form will send contacts into the specified list on your account’s sign-up form. The code below sends them to a new page after their information has been submitted.

Copy and paste code strip:

Join our email list to receive updates and specials!

Unminified code:
constant contact power user tips hacks
The above sends the contact to Constant Contact. Replace the link with your own URL and your own custom “Thank you for signing up to our form” webpage, beginning with HTTP.

If there’s an error when a contact’s submitted, the above form will send them to the Constant Contact page, visitor2.constantcontact.com, displaying an error to the user.

To keep the user on their current page when they submit the form, a more advanced script is needed. An example jQuery is included below.

1. jQuery CDN that’s inserted into the header of your page

Copy and paste code strip:

Unminified code:

jquery cdn

2. The script that processes the form


Copy and paste code strip:

$(document).ready(function() {
// process the form
$("#ctct_signup").submit(function(event) {
// get the form data
var formData = $("#ctct_signup").serialize();
// process the form
$.ajax({
type : 'POST', // HTTP method, always use POST for our form
url : 'https://visitor2.constantcontact.com/api/signup',
data : formData, // serialized form data
dataType : 'json', // the type of data we expect back from the server
success: function(data){
$("#ctct_signup").replaceWith("

Thank you for joining our mailing list!

“); }, error: function(response) { $(“#ctct_signup”).replaceWith(”

The server returned an error: Status ” + response.status + “: ” + response.responseText + ”

“); } }); // stop the form from submitting the normal way and refreshing the page event.preventDefault(); }); });

Unminified code:
constant contact power user tips
3. The HTML form (that your contact will see)


Join our email list to receive updates and specials!

Copy and paste code strip:

Join our email list to receive updates and specials!

Unminified code:
constant contact power user tips

Note that there are three parts to this form: the jQuery header, the jQuery script, and the HTML form.

Source: http://techblog.constantcontact.com/api/release-updates/announcing-a-new-signup-form-post-url/

How to Test Your XML

Using RESTClient as a tool enables you to test your XML as well as how you’re using the APIs in Constant Contact. It’s an easy way to test individual calls outside your program to see if you’re correctly calling APIs. If you’ve made an error you’ll be provided with detailed error messages.

To start with, download and install the RESTClient here.

Then, set up your authentication information in Constant Contact by clicking the “Auth” tab before checking “BASIC” and unchecking “Preemptive”.

Enter {API KEY}%{Constant Contact username} in the “Username” section and your password in the relevant field.

Using RESTClient

You’ll tend to work with the tabs – “Method”, “Headers”, and “Body”.

In the “Method” tab – choose the appropriate method. If you’re using the GET method, you won’t need to use the other two tabs. But if you’re using POST or PUT, you’ll need to put your XML in the “Body” tab, adding “application/atom+xml” in the “Content-Type” header. If you’re trying to run GET followed by POST or PUT, you don’t need to delete the contents in the “Body” and “Headers” tabs as they’ll be ignored.

In URL, enter your API call as follows (always using https instead of http):

https://api.constantcontact.com/ws/customers/{username}/lists

Examples

1. Getting a list of contacts

Choose “GET” on the “Method” tab.

Enter https://api.constantcontact.com/ws/customers/testuser/contacts in the URL.

Hit the button that displays the “>>” icon.

Now, the RESTClient will display a response status in the lower pane – this should be 200 OK.

If your call was successful, in the BODY tab you can inspect the response body. This is often useful when putting together a Request Body for an update (PUT) or create (POST) command.

2. Creating a new contact list

Choose “POST” on the “Method” tab.

Enter “Content-Type” in the “Key” section of the “Headers” tab, and “application/atom+xml” as the “Value”. To add, just hit the plus button.

Enter your XML entry on the “Body” tab for your new contact list.

In the URL, put – https://api.constantcontact.com/ws/customers/testuser/lists

Hit the button that displays the “>>” icon.

Source –
https://community.constantcontact.com/t5/Documentation/How-To-Use-RESTClient/ba-p/24915