Last active
December 17, 2015 05:59
-
-
Save dsjellz/5562021 to your computer and use it in GitHub Desktop.
Add a new contact including an address and custom field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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