Updating Contact 400 error.

Regular Participant

Updating Contact 400 error.

Hi. 

 

I'm using the PHP wrapper for ConstantContact (found at https://github.com/constantcontact/ctct_php_library ) and am running into an issue when updating contacts information. The error presented is here: 

 

---

UPDATING CONTACT Constant Contact HTTP Request Exception: Error 400: The request contains errors in the common Atom sections, which lie outside <entry> or <Content>, such as <feed>, <id>, <author> or <updated>

---

 

The associated PHP code that generated the error is here: http://cl.ly/code/2U2K08370M2d

The XML output: http://cl.ly/code/36422Z3P1b22

The PHP print_r output for the contact: http://cl.ly/code/1J0f1J090D2D

 

Any help in solving this issue would be greatly appreciated. 

3 REPLIES 3
Employee

Hi,

 

Looking at the XML, the most obvious issue is the lists node.  You should be supplying the full list url like this:

 

 <ContactLists>
<ContactList id="http://api.constantcontact.com/ws/customers/joesflowers/lists/1" />
</ContactLists>

 

When updating a contact, we recommend doing a GET to retrieve the XML, then modify only what's necessary and do a PUT.  I'll usually make changes in increments afterwards if a 400 is received, which means the system didn't understand something about the XML supplied.  That way you can narrow down the node(s) with the issue.

 

Best Regards,

Shannon W.

API Support Specialist

Also, here is my PHP code to update a contact using the wrapper:

 

<?php

session_start ();
require_once 'ConstantContact.php';
require_once 'config.php';

$ConstantContact = new ConstantContact("oauth2", $apikey, $username, $accessToken);  //OR
//$ConstantContact = new ConstantContact("basic", $apikey, $username, $password);
//Supply your credentials--API Key and other details--in config.php

// Get potential contact lists
$lists = $ConstantContact->getLists();
// Lists are returned in multidimentional arrays 0 being the list, and 1 being the next50

// Email address here is used for testing purposes
$emailAddress = "test_12132012@example.com";

// Search for our new Email address
$search = $ConstantContact->searchContactsByEmail($emailAddress);

// Gather data from our previous search and store it into a data type
$contactObj = $ConstantContact->getContactDetails($search[0]);

// We need to get the old list and add a new list to it as
// this request requires a PUT and will remove the lists
// as they are stored in an array
array_push($contactObj->lists, $lists['lists'][1]->id );

//Set the opt in value
$contactObj->optInSource = "ACTION_BY_CONTACT";
$contactObj->firstName = 'firstname';
$contactObj->lastName = 'CTCTlastname';
// Update the contact and DONE
$UpdateContact = $ConstantContact->updateContact($contactObj);

echo ("Contact updated.");

?>

 

I hope that helps!

 

Best Regards,

Shannon W.

API Support Specialist

thanks

Its working fine

Developer Portal

View API documentation, code samples, get your API key.

Visit Page