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.
All of API URLs start with the following base part, https://api.constantcontact.com/v2
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.
In this file, we created a ConstantContact object in OnApplicationStart function to access the ConstantContact component's methods.
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.
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.
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:
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 | 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. |
{ "name": "Hot Opportunities", "status": "ACTIVE" }
Use this endpoint to retrieve a collection of existing contact lists.
GET: https://api.constantcontact.com/v2/lists
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 . |
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 | Values | Description |
---|---|---|
action_by | ACTION_BY_OWNER(default) or ACTION_BY_VISITOR | The following values are we need to use:
|
api_key | REQUIRED; The API key for the application API_key. | |
Request Body | JSON Values of Contact Details | JSON Request Body for the Application. |
Gets one or more contacts in the account, depending on the query parameters used:
email
query parameter URL encode
the email address, as with all query parameters values, to ensure proper system response.date/time
specified by the modified_since
query parameter. This is useful for syncing contacts across applications.status
query parameterGET: https://api.constantcontact.com/v2/contacts
Parameters | Values | Description |
---|---|---|
api_key | REQUIRED; The API key for the application API_key. | |
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. |