Updating contact address


Updating contact address

Hi All,


Until recently below code was working fine. When an email already exists, the code tries to update other details along with contact address, the code snippet as follows:


$contact = $response->results[0];
$contact->first_name = 'The Value';
$contact->last_name = 'The Value';
$contact->company_name = 'The Value';
$contact->home_phone = 'The Value';
$contact->addresses[0]    =    array('city'=>'The Value', 'line3'=>'The Value');
$returnContact = $cc->updateContact(ACCESS_TOKEN, $contact);


But now, it's giving following error:


    [0] => Array
            [error_key] => http.status.bad_request
            [error_message] => Bad request.



If I comment out the line $contact->addresses[0]    =    array('city'=>'The Value', 'line3'=>'The Value'); from above code snippet, everything works fine. But I need to update the city and line3 of the existing user's contact address. How can I achieve this? Can someone please help me?




Thanks for posting.  Its very strange that you're running into a problem with that line of code.  I tried the whole block myself and the line works fine and I verified that it correctly updates the two entries in the address array.  If you want to PM me the complete source that is not working or send an email to webservices@constantcontact.com, I can help you more effectively. 




Andrew B.

Constant Contact

API Support

Dear Andrew,


Thanks for your reply.


It's not only when updating, but also when trying to create a new contact using a new email id, city, state and other user details, the same error shows up. Most strange thing is the same piece of code was working until this problem popped up and as a matter of fact, I already registered many email addresses as part of my testing process with the same peace of code. For your reference I am attaching my php file which I downloaded one month ago from https://github.com/constantcontact/php-sdk/blob/master/examples/addOrUpdateContact.php along with all library and just added a few fields like city, state, home_phone, company etc. I am kind of lost and clueless about the issue, please help. Can you please check my php file?


Thank you

Kind Regards

Occasional Participant

I'm running into the same problem, and I'm not sure why this has all of a sudden stopped working. Here is the code I'm using. 


$cc = new \Ctct\ConstantContact($apiKey);

$response = $cc->getContactByEmail($accessToken, $email);

$contact = $response->results[0];

if(isset($_POST['zip_code'])) {
    if(count($contact->addresses)) {
        $contact->addresses[0]->postal_code = $_POST['zip_code'];
        $contact->addresses[0]->country_code = $_POST['country'];
    } else {
        $address = new \Ctct\Components\Contacts\Address();
        $address->postal_code = $_POST['zip_code'];
        $address->country_code = $_POST['country'];


I grabbed the contact JSON and tried it agains the API debugger, and both the debugger and the above PHP code result in the following error:


[{"error_key":"http.status.bad_request","error_message":"Bad Request"}]


I shortened the above code, but I am getting a valid contact back, and in my actual code I'm checking to make sure that's the case. Above is just the relevant portions of the code that are failing. I can update things like the name, but the addresses just fail.

Occasional Participant

For anyone that finds this thread, the fix was to add an 'address_type' value of 'UNKNOWN' when creating the address:


$address->address_type = 'UNKNOWN';


I added that and it worked fine.

Thanks for the help in troubleshooting this issue with us and for posting the resolution.  We are opening a defect now on this regression and hopefully will have it fixed soon.  While I'm glad there is a workaround, we do need to fix the defect as well to prevent the problem from impacting future developers.

Dave Berard
Senior Product Manager, Constant Contact
Developer Portal

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

Visit Page