Our v3 API is now available! Learn more by visiting the v3 developer portal.

Contacts Collection Endpoint

Use this endpoint to retrieve (GET) contacts in the user's account, or to create (POST) a new contact.

Methods:

Click a method to view its documentation

GET POST

DescriptionTOP

Privileges requiredcontacts:write

To create a new contact, the contact must have an email address and be assigned to a contact list. No other properties are required. Setting the action_by query parameter to ACTION_BY_VISITOR will trigger an Autoresponder message welcoming the new subscriber to your list. Learn more about Autoresponder.

There are several features of the new contact management system that are not currently supported in the API. Check here for the details.

Code Sample using the PHP SDK

$contact = new Contact();
   $contact->addEmail($_POST['Email']);
   $contact->addList("999999999");
   $contact->first_name = $_POST['Name'];
   $contact->company_name = $_POST['company_name']; 
   $contact->job_title = $_POST['Title'];
   $contact->work_phone = $_POST['Phone'];
   $state = $_POST['State'];
   $contact->addAddress(Address::create( array("address_type"=>"BUSINESS","line1"=>$street,
  "city"=>$city,"state"=>$state,"postal_code"=>$zip)));

Code Sample using Ruby SDK

#gem install constantcontact

require 'yaml'
require 'constantcontact'

class ContactExample

  def initialize()
    cnf = YAML::load(File.open('config/config.yml'))
    @cc = ConstantContact::Api.new(cnf['api_key'], cnf['oauth_token'])
  end

  def add_contact( contact_json )
    @cc.add_contact( contact_json )
  end

  def get_lists
    @cc.get_lists()
  end

end
class AddContactTest
  def do()
    contact_example = ContactExample.new
    contact_list = contact_example.get_lists[0].id
    puts "Add what email address?"
    email_address = gets.chomp
    puts "Adding #{email_address} to Contact List #{contact_list}"

    list_to_add_to = ConstantContact::Components::ContactList.new
    list_to_add_to.id = contact_list

    new_contact = ConstantContact::Components::Contact.new
    new_contact.add_email(ConstantContact::Components::EmailAddress.new(email_address))
    new_contact.add_list(list_to_add_to)
    new_contact.first_name = 'Example'
    new_contact.last_name = 'User'

    #input = "{ 'email_addresses':[{'email_address':'#{email_address}'}], 'lists':[{'id':'#{contact_list}'}], first_name':'Example', 'last_name':'User'}"
    #puts input
    puts new_contact.to_json

    puts contact_example.add_contact( new_contact ).to_json

  rescue RestClient::BadRequest => e
    puts "#{e.http_code} - #{e.http_body}"
  end
end
AddContactTest.new.do

POST: https://api.constantcontact.com/v2/contacts

Test API

Example JSON Request BodyTOP


Example ResponseTOP