function cc::create_contact in Constant Contact 6.2
Same name and namespace in other branches
- 6.3 class.cc.php \cc::create_contact()
- 7.3 class.cc.php \cc::create_contact()
* Creates a new contact * * @access public
File
- ./
class.cc.php, line 561
Class
- cc
- @file
Code
function create_contact($email, $lists = array(), $additional_fields = array()) {
$lists_url = str_replace('https:', 'http:', $this->api_url . "lists");
// build the XML post data
$xml_post = '
<entry xmlns="http://www.w3.org/2005/Atom">
<title type="text"> </title>
<updated>2008-07-23T14:21:06.407Z</updated>
<author></author>
<id>data:,none</id>
<summary type="text">Contact</summary>
<content type="application/vnd.ctct+xml">
<Contact xmlns="http://ws.constantcontact.com/ns/1.0/">
<EmailAddress>' . $email . '</EmailAddress>
<OptInSource>' . $this->action_type . '</OptInSource>
';
if ($additional_fields) {
foreach ($additional_fields as $field => $value) {
$xml_post .= "<{$field}>{$value}</{$field}>\n";
}
}
$xml_post .= '<ContactLists>';
if ($lists) {
if (is_array($lists)) {
foreach ($lists as $k => $id) {
$xml_post .= '<ContactList id="' . $lists_url . '/' . $id . '" />';
}
}
else {
$xml_post .= '<ContactList id="' . $lists_url . '/' . $lists . '" />';
}
}
$xml_post .= '</ContactLists>';
$xml_post .= '
</Contact>
</content>
</entry>';
$this
->http_set_content_type('application/atom+xml');
$xml = $this
->load_url("contacts", 'post', $xml_post, 201);
if (isset($this->http_response_headers['Location']) && trim($this->http_response_headers['Location']) != '') {
return $this
->get_id_from_link($this->http_response_headers['Location']);
}
return false;
}