MitrahSoft is an Adobe offcial partner MitrahSoft is Lucee offcial partner & core contributing developer

Constant Contact API Integration Using ColdFusion

The Constant Contact API v2 is built on HTTP, uses Representational State Transfer (REST) design principles and supports JavaScript Object Notation (JSON) data-interchange format. Constant Contact REST API is simple to use, direct and concise, lightweight and optimized.

constant contact email marketing API ColdFusion Integration
Prerequisites
  1. To use Constant Contact, we must have Constant Contact User Account and Constant Contact Mashery Account(Developer)
  2. After creation of accounts we will know API Key and Client SecretKey and need to register your application for this (Mashery)account.
  3. After that, application to access the Constant Contact API, it needs to have a valid Access Token for customer grants the application access to their account.
Base URL

All of API URLs start with the following base part, https://api.constantcontact.com/v2

Sample Demo

In this blog post, we are going to illustrate how to integrate Constant Contact REST API and how to get access token for accessing their application. Some sample API calls for ADD and GET the Contact List in constant contact using ColdFusion.

Application.cfc

In this file, we created a ConstantContact object in OnApplicationStart function to access the ConstantContact component's methods.

constantContact.cfc

This ColdFusion CFC has all needed functions for get access token and make simple API call for add, get Contacts from ConstantContact. We have just hardcoded API Key , Client SecretKey & RedirectUrl values in init() function. But we need pass these as arguments too. In each function, we provided proper attributes, that will explain each arguments purposes.

Using OAuth 2.0 to Get Access Token

The OAuth 2.0 server flow is used whenever a Constant Contact account uses your integration for the first time. The Constant Contact user must login to their account and give permission to your application to access their Constant Contact account. The application makes an Authentication Request to the Authorization server, and the server returns the access token to their application with Authorization Code and UserName on the URL. After getting the code again Application make an Access Token request using Authorization Code. Then Authentication Server has given the response with Access Token.

Authorization Request

An Authorization Request is formed as a GET call to the authorize API endpoint

https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize
Parameters Values Description
response_type token The value token tells the authentication server to send an access token to a web application.
client_id Identifies the client that is making the request to the server. This value must always be set to the exact value of the API_key.
redirect_uri Authorization Server where to authentication code to send the user once access is granted.
oauthSignup true or false(default) Use oauthSignup=true to show a sign up link on the login page.
NOTE:This parameter is ignored when using newUser parameter
newUser true or false(default) Use newUser=true to send users who do not have a Constant Contact account to the account signup page.

Example Authorization Request:

constant contact oAuth2 ColdFusion flow
Add New ContactsList

Use this endpoint to create a New Contact List. An account can have a maximum of 1000 lists. For Creation of new contact list, you must include the Name of the list, and the Status of the list.

POST: https://api.constantcontact.com/v2/lists
Parameters Used in Add New ContactsList
Parameters Values Description
api_key REQUIRED; The API key for the application API_key.
Request Body JSON Values of Contact List Details JSON Request Body to add the new contact list for our the Application.
Example JSON Request Body
{ "name": "Hot Opportunities", "status": "ACTIVE" }
Example Response
addContactList response
Get ContactList

Use this endpoint to retrieve a collection of existing contact lists.

GET: https://api.constantcontact.com/v2/lists
Parameters Used in Get ContactList
Parameters Values Description
api_key REQUIRED; The API key for the application API_key.
include_list_id true or false (default) include_list_id=true returns the uuid formatted list_id property, which is the list unique identifier in the V3 API. Useful for migrating V2 API integrations to the V3 API.
Example Respose
getContactList response
Add New Contact

To create a new contact, the contact must have an email address and be assigned to a contact list. But we need to identifies who originated the action of adding the contact. For this we'll using the extra argument to add contact as account or subscriber.

Use this below endpoint to create (POST) a new contact.

POST: https://api.constantcontact.com/v2/contacts
Parameters Used in Add New Contact
Parameters Values Description
action_by ACTION_BY_OWNER(default) or ACTION_BY_VISITOR

The following values are we need to use:

  • ACTION_BY_OWNER - contact was added by the account and not the subscriber.
  • ACTION_BY_VISITOR - contact was added by the contact.
api_key REQUIRED; The API key for the application API_key.
Request Body JSON Values of Contact Details JSON Request Body for the Application.
Example JSON Request Body
Example Respose
addNewContact response
Get Contacts

Gets one or more contacts in the account, depending on the query parameters used:

  • All contacts in a user's account (no query parameters used)
  • A specific contact specified by the email query parameter
    • URL encode the email address, as with all query parameters values, to ensure proper system response.
    • The API is not able to return a contact by email address call if a contact's email address has been deleted in the product UI
  • Only the contacts that have been modified on or after the date/time specified by the modified_since query parameter. This is useful for syncing contacts across applications.
  • Only the contacts with a status specified by the status query parameter
GET: https://api.constantcontact.com/v2/contacts
Parameters Values Description
api_key REQUIRED; The API key for the application API_key.
email Email address for the particular contact specify the EXACT contact by email address to retrieve information.
limit 1 - 500 default(50) Specifies the number of results displayed per page of output.
Example response
getContacts response