Edit Contact

Highlighted
Occasional Contributor

Edit Contact

If an existing contact is edited via the API, the state seems to be dropped. Viewing the address from within the Constant Contact account shows that the state field is empty.

 

I've confirmed that a valid state and matching state_code are being sent with the edit request (Louisianna and LA).

 

This does not happen when adding address. The code being used is very similar:

 

//add new contact

$contact = new Contact();
$contact->addEmail($_POST['email']);
$contact->addList($_POST['list']); 
$contact->first_name = $_POST['first_name'];
$contact->last_name = stripslashes($_POST['last_name']);
$contact->company_name = stripslashes($_POST['company_name']);
$contact->addAddress(Address::create( array("address_type"=>$_POST['address_type'],"line1"=>$_POST['street'],"line2"=>$_POST['street2'],"line3"=>$_POST['street3'],"city"=>$_POST['city'],"state"=>$_POST['state'[,"state_code"=>$_POST['state_code'],"postal_code"=>$_POST['zip'])));

$returnContact = $cc->addContact(ACCESS_TOKEN, $contact, true);

 

//edit existing contact

$contact = new Contact();
$contact->addEmail($_POST['email']);
$contact->addList($_POST['list']); 
$contact->first_name = $_POST['first_name'];
$contact->last_name = stripslashes($_POST['last_name']);
$contact->company_name = stripslashes($_POST['company_name']);
$contact->addAddress(Address::create( array("address_type"=>$_POST['address_type'],"line1"=>$_POST['street'],"line2"=>$_POST['street2'],"line3"=>$_POST['street3'],"city"=>$_POST['city'],"state"=>$_POST['state'[,"state_code"=>$_POST['state_code'],"postal_code"=>$_POST['zip'])));

$returnContact = $cc->updateContact(ACCESS_TOKEN, $contact, true);

 

4 REPLIES 4
Highlighted
CTCT Employee

Re: Edit Contact

Hi Thomas,

 

Sorry for the long delay again. I tested this a few different ways, and I can see a situation where the state isn't displayed in the UI even though it's sent thorugh the API.

 

If the 'state,' but not the 'state_code,' is sent over, the UI doesn't show the state. The UI only displays what is stored in the state code, because it maps the state code to the full name of the state.

 

If you were sending over BOTH, I tested this, and at the API level, we return a 400 error if you send over either a mis-spelled or non-valid state code and/or state. If you were trying to include both, and one was misspelled, like "Louisianna," the PHP SDK may have caught that error, or tried to match the state code with the state name, and when it couldn't do so, not sent the value(s) through, and therefore, you might not have seen it in the account. I did test this only on an existing contact, since that's where you said the problem lies.

 

Are you consistently seeing this behavior where you're sure you have the 2 values matching and correct? If so, let me know and I'm happy to test. Thanks!

 

Best Regards,

Shannon Wallace

Partner API Support Engineer

Highlighted
Occasional Contributor

Re: Edit Contact

Thank you for the reply.

 

I first added a contact with using the API with the following values:

 

$contact = new Contact();
$contact->addEmail(bigrocklanterns@gmail.com);
$contact->first_name = 'Barbara';
$contact->last_name = 'Williams';
$contact->company_name = 'Big Rock Lanterns';
$contact->addAddress(Address::create( array("address_type"=>BUSINESS,"line1"=>170 Soda Pop Ln,"line2"=>$_POST['street2'],"line3"=>$_POST['street3'],"city"=>Murphy,"state"=>North Carolina,"state_code"=>NC,"postal_code"=>28906)));

 

Everything was fine.

 

I then edited the contact using the API, changing only the company name:

 

$contact->first_name = 'Barbara';
$contact->last_name = 'Williams';
$contact->company_name = 'Big Rock Lanterns, LLC';
$contact->addAddress(Address::create( array("address_type"=>BUSINESS,"line1"=>170 Soda Pop Ln,"line2"=>$_POST['street2'],"line3"=>$_POST['street3'],"city"=>Murphy,"state"=>North Carolina,"state_code"=>NC,"postal_code"=>28906)));

 

The State disappears, both in my app when listing the contacts and when viewed within my Constant Contact account.

 

The actual values sent to the API for state and state_code are: North Carolina and NC.

 

If I edit the address from within my Constant Contact account, entering NC for the State/Province, it works correctly.

 

Regarding the mispelling of Louisiana, I edited the contact (with the API) using the correct spelling "Louisiana" and "LA" for the state_code, with the same result. The state was dropped from the address.

 

Let me know if you need more information from my end to determine what may cause this behavior.

Highlighted
Honored Contributor

Re: Edit Contact

Hello Tomas,

 

I have been reviewing this in detail and trying to reproduce this error. I have tried a number of ways to accomplish this, but I have not been able to reproduce the problem when updating a contact. Is it possible for you to send us some additional info so that we can dig into the exact details of what is happening? It would be best to send the following info to webservices@constantcontact.com :

  • Contact Email Address
  • The value of $contact->toJson(). This can be captured in your application just before you call $cc->updateContact
  • Constant Contact account username

 

With this information that should give me what we need to find out exactly what is happening and ensure that it is addresses properly! If you have any questions, please let me know.

 

Sincerely,

Elijah G.
API Support Engineer
Highlighted
Occasional Contributor

Re: Edit Contact

I have sent the info requested to webservices@constantcontact.com.

 

Thank you for following up on this issue.

Developer Portal

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

Visit Page

Constant Contact Would Like To Hear From You!

We want to hear from customers like you about your favorite features and how they have helped your business or organization. Tell us by answering a few questions in...

Read More
Featured