Skip to content

Instantly share code, notes, and snippets.

@dsjellz
Last active December 17, 2015 05:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsjellz/5562021 to your computer and use it in GitHub Desktop.
Save dsjellz/5562021 to your computer and use it in GitHub Desktop.
Add a new contact including an address and custom field
<?php
require_once '../src/Ctct/autoload.php';
use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\CustomField;
use Ctct\Components\Contacts\Address;
use Ctct\Exceptions\CtctException;
// Enter your Constant Contact APIKEY and ACCESS_TOKEN
define("APIKEY", "YOUR API KEY");
define("ACCESS_TOKEN", "YOUR ACCESS TOKEN");
$cc = new ConstantContact(APIKEY);
$contact = new Contact();
$contact->addEmail('address@example.com');
$contact->addList('1');
$contact->first_name = 'Joe';
$contact->last_name = 'Shmoe';
// Create and add a new address
$address = new Address();
$address->address_type = "BUSINESS"; // PERSONAL, BUSINESS, UNKNOWN
$address->line1 = "1601 Trapelo Rd";
$address->line2 = "Third Floor";
$address->line3 = "Constant Contact";
$address->city = "Waltham";
$address->state_code = "MA";
$address->postal_code = "02451";
$address->country_code = "US";
$contact->addAddress($address);
// Create and add a new Custom Field
$customField = new CustomField();
$customField->name = "CustomField1";
$customField->value = "CustomFieldValue";
$contact->addCustomField($customField);
try{
$returnContact = $cc->addContact(ACCESS_TOKEN, $contact);
} catch (CtctException $ex) {
print_r($ex->getErrors());
}
print_r($returnContact);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment