Introduction
Constant Contact is a leading expert in email marketing, providing small businesses with the tools they need to create effective campaigns. With a wide range of easy-to-use tools and features, Constant Contact makes it simple to design and execute successful email marketing strategies.
Default URLs:
-
Staging Path:
http://api.socialannexstaging.com/constant_contact/Constantcontactlib.php -
Production Path:
https://api.socialannex.com/constant_contact/Constantcontactlib.php
Available Functions:
createContact()
This function adds a contact to a specified contact list.
| Parameter Name | Parameter Description | Example |
|---|---|---|
| $accessToken | The authorization token (see Section 3.7 for details). | AcVhQBMMErURVZrJYG9VvaoAQrSL |
| $listId (required) | The ID of the contact list where the contact should be added. | 9e6431ae-19e9-11eb-a855-fa163e751802 |
| $email (required) | The email address of the contact. |
somebody@gmail.com |
| $fieldData (required) | An array of custom fields that map the contact's details. | array( "first_name"=>"matt", "birthday_month"=>"08", "birthday_day"=>"10", "ef73e0d8-2e86-11eb-9f27-fa163ea6032f"=>"1000", "f0dadc64-4453-11eb-9523-fa163e56233d"=>"0", "f0dcbdea-4453-11eb-9523-fa163e56233d"=> "04/03/2010", "f0de4ea8-4453-11eb-9523-fa163e56233d"=>"1", "f0dfceae-4453-11eb-9523-fa163e56233d"=>"04/03/2020", "fa664b5c-2e86-11eb-baff-fa163ea6032f"=>"500" ) |
updateContact()
This function is used to update an existing contact's information.
| Parameter Name | Parameter Description | Example |
|---|---|---|
| $accessToken | The authorization token (see Section 3.7 for details). | AcVhQBMMErURVZrJYG9VvaoAQrSL |
| $listId (required) | The ID of the contact list where the contact resides. | 9e6431ae-19e9-11eb-a855-fa163e751802 |
| $email (required) | The email address of the contact to be updated. | somebody@gmail.com |
| $fieldData (required) | An array containing the fields to be updated. |
array( fa163ea6032f"=>"1000", "f0dadc64-4453-11eb-9523-fa163e56233d"=>"0", "f0dcbdea-4453-11eb-9523-fa163e56233d"=> "04/03/2010", "f0de4ea8-4453-11eb-9523-fa163e56233d"=>"1", "f0dfceae-4453-11eb-9523-fa163e56233d"=>"04/03/2020", "fa664b5c-2e86-11eb-baff-fa163ea6032f"=>"500" ) |
addOrUpdateContact()
This method is used to either create a new contact or update an existing one.
Note: The function only updates the fields provided in the $fieldData parameter.
| Parameter Name | Parameter Description | Example |
|---|---|---|
| $accessToken | The authorization token (see Section 3.7 for details). | AcVhQBMMErURVZrJYG9VvaoAQrSL |
| $apiKey (required) | The API key provided by Constant Contact. | y5rdwwyggfpbza8znz878wmd |
| $email (required) | The email address of the contact. | somebody@gmail.com |
| $fieldData (required) | The array of fields to create or update. |
array( fa163ea6032f"=>"1000", "f0dadc64-4453-11eb-9523-fa163e56233d"=>"0", "f0dcbdea-4453-11eb-9523-fa163e56233d"=> "04/03/2010", "f0de4ea8-4453-11eb-9523-fa163e56233d"=>"1", "f0dfceae-4453-11eb-9523-fa163e56233d"=>"04/03/2020", "fa664b5c-2e86-11eb-baff-fa163ea6032f"=>"500" ) |
getFields()
This function retrieves all custom fields available for a contact list.
| Parameter Name | Parameter Description | Example |
|---|---|---|
| $accessToken | The authorization token (see Section 3.7 for details). | AcVhQBMMErURVZrJYG9VvaoAQrSL |
createFields()
This function creates a custom field for a contact list.
| Parameter Name | Parameter Description | Example |
|---|---|---|
| $accessToken | The authorization token (see Section 3.7 for details). | AcVhQBMMErURVZrJYG9VvaoAQrSL |
| $fieldLabel | The display name of the custom field shown in the UI. | Available Points |
| $fieldType | Specifies the type of data the custom field will accept (for example, string, date). | String |
refreshToken()
Access tokens expire automatically after 2 hours (7,200 seconds). This function is used to obtain a new access token after expiration.
| Parameter Name | Parameter Description | Example |
|---|---|---|
| $refresh_token | The refresh token (see Section 3.7 for details). | FSb0L49mzfthmjZD6yiwLi2hZ0cEOxtBom8cu3fjAH |
| $client_id | The client ID provided by Constant Contact. | 94efde99-e3be-491f-8e09-dac1ee9f5588 |
| $client_secret | The client secret provided by Constant Contact. | Hsne_mQqgQCgaz0-Lkl8XQ |
How to Get Access Token and Refresh Token:
To obtain an access token and refresh token, follow these steps:
- Visit the following URL:
https://api.socialannex.com/constant_contact/connect.php?site_id={siteid} - The account owner will be prompted to log in and allow your app to access their account.
- After login, the account owner will be redirected to your specified redirect URL with an authorization code appended as a query parameter.
- The response will contain both the access_token and refresh_token.
Example URL:
https://api.socialannex.com/constant_contact/connect.php?site_id=54640920
Example Usage of the Class:
$objectCCV3 = new Constantcontactlib();
$email_id = "sa.testint@gmail.com";
$data = array(
"first_name"=>"sa",
"birthday_month"=>"08",
"birthday_day"=>"10",
"ef73e0d8-2e86-11eb-9f27-fa163ea6032f"=>"1000",// Total spent
"f0dadc64-4453-11eb-9523-fa163e56233d"=>"0", //Activities Completed
"f0dcbdea-4453-11eb-9523-fa163e56233d"=> "04/03/2010",// Join date
"f0de4ea8-4453-11eb-9523-fa163e56233d"=>"1", //Optin Status
"f0dfceae-4453-11eb-9523-fa163e56233d"=>"04/03/2020",//Program Anniversary Date
"fa664b5c-2e86-11eb-baff-fa163ea6032f"=>"500"//total saved
);
$client_id="94efde99-e3be-491f-8e09-dac1ee9f5588";
$client_secret_key="Hsne_mQqgQCgaz0-Lkl8XQ";
$listId = "9e6431ae-19e9-11eb-a855-fa163e751802";
$result = $objectCCV3 ->addOrUpdateContact($getToken['access_token'], $listId, $email_id, $data);
Log in to Constant Contact
- To log in to Constant Contact, click on the following link:
https://login.constantcontact.com/ - This will open the login screen.
Create a List
To create a new list, follow these steps:
- Navigate to Contacts → Lists, as shown in the image below.
- Click the Create List button.
- A popup will appear.
- Enter the name of your list and click the Add List button.
This will create the list.
Create a Message
To create a new message, follow these steps:
- Navigate to Campaigns → Create, as shown in the image below.
- A popup will appear.
- Select Email Automation, then click Create Automated Series.
- A new window will open.
- Enter the name of your series and click the Save button.
- Follow the on-screen instructions to create the email.
Steps to Get API Key and Access Token
To get your API Key and Access Token, follow these steps:
- Click on My Applications, as shown in the window below.
- Click on New Application.
- A popup will appear.
- Enter the app name and click the Save button.
- The next window will open.
- Provide the Client ID to Annex Cloud.
- Click the Generate Secret button.
- This will generate your secret key.
- Provide the User Client ID and Client Secret to Annex Cloud.