Mitrahsoft
  • SERVICES
    • OUR SERVICES
      • SOFTWARE DEVELOPMENT
      • MOBILE DEVELOPMENT
      • BLOCKCHAIN DEVELOPMENT
      • SOFTWARE TESTING
      • CLOUD & DEVOPS SERVICES
      • PRODUCT DEVELOPMENT
      • OFFSHORE DEVELOPMENT
      • SOCIAL MEDIA MARKETING
      TECHNOLOGIES
      • COLDFUSION DEVELOPMENT
      • REACTJS DEVELOPMENT
      • VUEJS DEVELOPMENT
      • ANGULAR DEVELOPMENT
      • NODEJS DEVELOPMENT
      • PYTHON DEVELOPMENT
      • GOLANG DEVELOPMENT
      • GOLANG CORPORATE TRAINING
      COLDFUSION EXPERTISE
      • MURACMS EXPERTISE
      • COLDFUSION APP MIGRATION
      • COLDFUSION HOSTING & SUPPORT
      • CF LEGACY APP MAINTENANCE
      • COLDFUSION REST API
      • ECOMMERCE / SHOPPING CART SOLUTIONS
      • PRESIDECMS EXPERTISE
      MOBILE DEVELOPMENT
      • REACT NATIVE DEVELOPMENT
      • FLUTTER DEVELOPMENT
      • IONIC DEVELOPMENT
      • PHONEGAP DEVELOPMENT
  • ABOUT US
    • ABOUT MITRAHSOFT
    • OUR CLIENTS
    • TESTIMONIALS
    • PORTFOLIO
    • CAREERS
  • CONTACT US
  • BLOG
Adobe Solution PartnerLucee Solution Partner
Adobe Solution PartnerLucee Solution Partner
Adobe Solution PartnerLucee Solution Partner
  • OUR SERVICESSOFTWARE DEVELOPMENTMOBILE DEVELOPMENTBLOCKCHAIN DEVELOPMENTSOFTWARE TESTINGCLOUD & DEVOPS SERVICESPRODUCT DEVELOPMENTOFFSHORE DEVELOPMENTSOCIAL MEDIA MARKETING
    TECHNOLOGIESCOLDFUSION DEVELOPMENTREACTJS DEVELOPMENTVUEJS DEVELOPMENTANGULAR DEVELOPMENTNODEJS DEVELOPMENTPYTHON DEVELOPMENTGOLANG DEVELOPMENTGOLANG CORPORATE TRAINING
    COLDFUSION EXPERTISEMURACMS EXPERTISECOLDFUSION APP MIGRATIONCOLDFUSION HOSTING & SUPPORTCF LEGACY APP MAINTENANCECOLDFUSION REST API ECOMMERCE / SHOPPING CART SOLUTIONSPRESIDECMS EXPERTISE
    MOBILE DEVELOPMENTREACT NATIVE DEVELOPMENTFLUTTER DEVELOPMENTIONIC DEVELOPMENTPHONEGAP DEVELOPMENT
  • ABOUT MITRAHSOFTOUR CLIENTSTESTIMONIALSPORTFOLIOCAREERS
  • CONTACT US
  • BLOG

Constant Contact API Integration Using ColdFusion

HomeBlogConstant Contact API Integration Using ColdFusion
ColdFusionColdFusion-API-Integration

Constant Contact API Integration Using ColdFusion

M
Post by MitrahsoftPublished: Jan 25, 2019

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 API Integration Using Coldfusion

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.

cfml
component output="false" {

	this.name = "constantContactAPI";

	public any function onApplicationStart() {
      	APPLICATION.objCC = createobject( "component", "constantContact" ).init();
	}

}

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.

cfml
component output="false" displayname="ConstantContact" {

	public constantcontact function init() {

		variables.apiHost     = "https://api.constantcontact.com/v2/";
		variables.apiKey      = "xxxxxxxxxxxxxxxxxxxxxxxx";
		variables.secretKey   = "xxxxxxxxxxxxxxxxxxxxxxxx";
		variables.redirectUrl = "http://localhost:8501/CC/index.cfm";

		return this;
	}

	// Get the AccessToken here
	public any function getAccessToken(
		required string authCode
	) {

		var oAuthURL = "https://oauth2.constantcontact.com/oauth2/oauth/token";

		httpToken = New http(
			method  = "GET",
			charset = "utf-8",
			url     = oAuthURL
		);

		httpToken.addParam(
			type  = "url",
			name  = "grant_type",
			value = "authorization_code"
		);

		httpToken.addParam(
			type  = "url",
			name  = "code",
			value = arguments.authCode
		);

		httpToken.addParam(
			type  = "url",
			name  = "redirect_uri",
			value = variables.redirectUrl
		);

		httpToken.addParam(
			type  = "url",
			name  = "client_id",
			value = variables.clientKey
		);

		httpToken.addParam(
			type  = "url",
			name  = "client_secret",
			value = variables.secretKey
		);

		httpResponse = httpToken.send().getPrefix().fileContent;

		return httpResponse;
	}

	// ConstantContact List calls
	public function getLists(
		required string accessToken
	) {

		return get(
			endpoint    = "lists",
			accessToken = arguments.accessToken
		);
	}

	// get contacts from List
	public function getListContacts(
		required string listId,
		required string accessToken
	) {

		return get(
			endpoint    = "lists/" & arguments.listId & "/contacts",
			accessToken = arguments.accessToken
		);
	}

	// Performs a generic HTTP GET operation
	public any function get(
		required string endpoint,
		required string accessToken
	) {

		httpService = new http(
			url    = variables.apiHost & arguments.endpoint,
			method = "GET"
		);

		httpService.addParam(
			type  = "header",
			name  = "Authorization",
			value = "Bearer #arguments.accessToken#"
		);

		httpService.addParam(
			type  = "URL",
			name  = "api_key",
			value = variables.apiKey
		);

		httpContent  = httpService.send().getPrefix().fileContent;
		responseJson = deserializeJson(httpContent);

		return responseJson;
	}

	// To add the new contact lists
	public function addContactList(
		required string accessToken,
		required string bodyData
	) {

		return post(
			endpoint    = "lists",
			accessToken = arguments.accessToken,
			bodyData    = arguments.bodyData
		);
	}

	// To add the new contact of the specified list
	public function addContacts(
		required string accessToken,
		required string bodyData
	) {

		return post(
			endpoint    = "contacts",
			accessToken = arguments.accessToken,
			bodyData    = arguments.bodyData
		);
	}

	// Performs a generic HTTP POST operation
	public any function post(
		required string endpoint,
		required string accessToken,
		required string bodyData
	) {

		httpService = new http(
			url    = variables.apiHost & arguments.endpoint,
			method = "POST"
		);

		httpService.addParam(
			type  = "header",
			name  = "Authorization",
			value = "Bearer #arguments.accessToken#"
		);

		httpService.addParam(
			type  = "header",
			name  = "Content-Type",
			value = "application/json"
		);

		httpService.addParam(
			type  = "URL",
			name  = "api_key",
			value = variables.apiKey
		);

		httpService.addParam(
			type  = "body",
			name  = "data",
			value = arguments.bodyData
		);

		var httpServiceRequest = httpService.send().getPrefix().filecontent;
		responseJson = deserializeJson(httpServiceRequest);

		return responseJson;
	}

}

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

ParametersValuesDescription
response_typetokenThe 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.
oauthSignuptrue 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
newUsertrue 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:

cfml
<cfset oAuthAuthorizeURL = "https://oauth2.constantcontact.com/oauth2/oauth/siteowner/authorize">
<cfoutput>
<a href="#oAuthAuthorizeURL#?response_type=code&client_id=xxxxxxxxxxxxxxx&redirect_uri=http://localhost:8501/CC/index.cfm">
	Click here to Get Access token
</a>
</cfoutput>
<cfscript>
	// Get accessToken
	accessToken = {};
	if( structKeyExists( url, "code" ) ){
		accessToken = APPLICATION.objCC.getAccessToken(
			authCode = url.code
		);
		writeDump( accessToken );
		abort;
	}
</cfscript>

Constantcontact O Auth2 Cold Fusion 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

ParametersValuesDescription
api_key REQUIRED; The API key for the application API_key.
Request BodyJSON Values of Contact List DetailsJSON Request Body to add the new contact list for our the Application.
cfml
<cfscript>
// Add a Contact List in to constantcontact using ColdFusion
bodyData = {
	"name": "TestMitrah List",
	"status": "ACTIVE"
};

addContactList = APPLICATION.objCC.addContactList(
	accessToken = '<YOUR_ACCESS_TOKEN>',
	bodyData = serializeJSON( bodyData )
);
writeDump(addContactList);abort;
</cfscript>

Example JSON Request Body

{ "name": "Hot Opportunities", "status": "ACTIVE" }

Example Response
Add Contact List 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

ParametersValuesDescription
api_key REQUIRED; The API key for the application API_key.
include_list_idtrue 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.
cfml
<cfscript>
	// Get Contact List from constantcontact using ColdFusion
	getContactList = APPLICATION.objCC.getLists(accessToken = '<YOUR_ACCESS_TOKEN>');
	writeDump(getContactList);abort;
</cfscript>

Example Response

Get List 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

ParametersValuesDescription
action_byACTION_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 BodyJSON Values of Contact DetailsJSON Request Body for the Application.

Example JSON Request Body

cfml
<cfscript>

// Add Contact into constantcontact using ColdFusion
bodyData = {
	"lists": [{
		"id": "1469817250"
	}],
	"job_title": "ForTestingCC",
	"last_name": "Mitrah",
	"work_phone": "555-555-5555",
	"first_name": "testing",
	"company_name": "Mitrahsoft",
	"cell_phone": "555-555-5555",
	"confirmed": "false",
	"addresses": [{
		"city": "Kovilpatti",
		"postal_code": "K8b 5W6",
		"address_type": "BUSINESS",
		"line1": "47 Shawmut Ave.",
		"country_code": "India",
		"state_code": "TN"
	}],
	"home_phone": "555-555-5555",
	"email_addresses": [{
		"email_address": "testmitrah@example.com"
	}],
	"fax": "555-555-5555"
};

addContact = APPLICATION.objCC.addContacts(
	accessToken = '<YOUR_ACCESS_TOKEN>',
	bodyData = serializeJSON( bodyData )
);
writeDump( addContact );
abort;
</cfscript>

Example Response
Add Contact 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
ParametersValuesDescription
api_key REQUIRED; The API key for the application API_key.
emailEmail address for the particular contactspecify the EXACT contact by email address to retrieve information.
limit1 - 500 default(50)Specifies the number of results displayed per page of output.
cfml
<cfscript>
// Get all contacts from a constantcontact list using ColdFusion
getContact = APPLICATION.objCC.getListContacts(
	accessToken = '<YOUR_ACCESS_TOKEN>',
	listId = '1469817250'
);
writeDump(getContact);abort;
</cfscript>

Example response
Get Contact Response

Tags

ADYENAMAZON-SESANDROIDAPACHEAPACHE-JMETERAWSBARCODE-SCANNERCOLDBOXCOLDFUSIONCOLDFUSION-API-INTEGRATIONCOLDFUSIONBUILDERECHARTSEVENT-GATEWAYFFMPEGFW1JQUERYJSOUPLUCEEMURACMSMURACMS-THEMENODEJSONESIGNALOSSPAYFLOW-PROPAYMENT-GATEWAYPAYPALPRESIDECMSPUPPETEERRAILORAZUNAREACTJSREACTNATIVERESTSASS-COMPILATIONSEMANTIC-UISUBLIMETEXTTINYMCETWILIOYUI-LIBRARY

Archives

JAN 20DEC 19AUG 19JUL 19JUN 19MAY 19APR 19MAR 19FEB 19JAN 19DEC 18NOV 18OCT 18MAR 16NOV 15SEP 15MAY 15MAY 14OCT 13JUN 13MAY 13APR 13MAR 13FEB 13JAN 13

Follow us

Mitrahsoft
United StatesUnited States

Hurst, Texas, United States

+1 (817) 606-8684usa-sales@mitrahsoft.com

IndiaIndia

Head Office

126G2/5, Thiru malai nagaram,
Kovilpatti - 628 501

Madurai

1/B, 2nd & 3rd floor, GV Complex,

Bye Pass Road, SS Colony,

Madurai - 625 016

Coimbatore

2nd Floor, Sri Narmadha Towers,

Murugan Nagar Rd, Thoppampatti Pirivu,

 K. Vadamadurai, Coimbatore - 641 017

+91 9092480924

business@mitrahsoft.com

ColdFusion
  • eCommerce / Shopping Cart Solutions
  • Payment Gateway Integrations
  • Shipping API Integrations
  • ColdFusion Development Services
  • REST API Development
  • MuraCMS Plugin Creation & Personalization
Technology Services
  • ReactJS Development
  • VueJS Development
  • AngularJS Development
  • NodeJS API Development
  • Python Development
  • Golang Development
  • React Native Development
  • D3.JS data Visualization
Other Services
  • Software Development
  • Mobile Development
  • Blockchain Development
  • Cloud & Devops Services

Connect with MitrahSoft

Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field
Please fill out this field

© 2026 All Rights Reserved. MitrahSoft Solutions Pvt Ltd

Home|About Us|Careers