I am getting an error message which I don't understand:
Array
(
[0] => Array
(
[error_key] => http.status.conflict
[error_message] => There was a conflict between the supplied data and the existing resource.
)
)
my form is pretty simple - just want to capture email address, subscirbe to a single list and the second issue I have is I want to add the data for customfield1
here is my form:
<!DOCTYPE HTML>
<html>
<head>
<title>Constant Contact API v2 Add/Update Contact Example</title>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">
</head>
<?php
require_once 'src/Ctct/autoload.php';
use Ctct\ConstantContact;
use Ctct\Components\Contacts\Contact;
use Ctct\Components\Contacts\ContactList;
use Ctct\Components\Contacts\EmailAddress;
use Ctct\Exceptions\CtctException;
define("APIKEY", "--REDACTED--");
define("ACCESS_TOKEN", "--REDACTED--");
$cc = new ConstantContact(APIKEY);
// attempt to fetch lists in the account, catching any exceptions and printing the errors to screen
try{
$lists = $cc->getLists(ACCESS_TOKEN);
} catch (CtctException $ex) {
foreach ($ex->getErrors() as $error) {
print_r($error);
}
}
// check if the form was submitted
if (isset($_POST['email']) && strlen($_POST['email']) > 1) {
$action = "Getting Contact By Email Address";
try {
// check to see if a contact with the email addess already exists in the account
$response = $cc->getContactByEmail(ACCESS_TOKEN, $_POST['email']);
// create a new contact if one does not exist
if (empty($response->results)) {
$action = "Creating Contact";
$contact = new Contact();
$contact->addEmail($_POST['email']);
$contact->addList($_POST['list']);
$contact->first_name = $_POST['first_name'];
$contact->last_name = $_POST['last_name'];
$returnContact = $cc->addContact(ACCESS_TOKEN, $contact);
// update the existing contact if address already existed
} else {
$action = "Updating Contact";
$contact = $response->results[0];
$contact->addList($_POST['list']);
$contact->first_name = $_POST['first_name'];
$contact->last_name = $_POST['last_name'];
$returnContact = $cc->updateContact(ACCESS_TOKEN, $contact);
}
// catch any exceptions thrown during the process and print the errors to screen
} catch (CtctException $ex) {
echo '<span class="label label-important">Error '.$action.'</span>';
echo '<div class="container alert-error"><pre class="failure-pre">';
print_r($ex->getErrors());
echo '</pre></div>';
die();
}
}
?>
<body>
<div class="well">
<h3>Add or Update a Contact</h3>
<form class="form-horizontal" name="submitContact" id="submitContact" method="POST" action="dp.cc.subscribe.php">
<div class="control-group">
<label class="control-label" for="email">Email</label>
<div class="controls">
<input type="email" id="email" name="email" placeholder="Email Address">
</div>
</div>
<div class="control-group">
<label class="control-label" for="list">List</label>
<div class="controls">
<select name="list">
<option value="1">delanceyplace.com</option>
<?php
// foreach ($lists as $list) {
// echo '<option value="' . $list->id . '">' . $list->name . '</option>';
// }
?>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">
<div class="controls">
<input type="submit" value="Submit" class="btn btn-primary"/>
</div>
</label>
</div>
</form>
</div>
<!-- Success Message -->
<?php if (isset($returnContact)) {
echo '<div class="container alert-success"><pre class="success-pre">';
print_r($returnContact);
echo '</pre></div>';
} ?>
</body>
</html>
THanks for your help!
Craig
... View more