addAddress

Participant

addAddress

Hi, I'm using the API v2. I am able to POST new contact name and email info but not address info. I am using a the PHP-sdk with a custom HTML form. The relevant code is as follows:

 

$contact = new Contact();
$contact->addEmail($_POST['email']);
$contact->addList("138");
$contact->last_name = $_POST['name'];

 

$address = new Address();
$address->address_type = "UNKNOWN";
$address->line1 = $_POST['street'];
$address->city = $_POST['city'];
$address->state_code = $_POST['state'];
$address->postal_code = $_POST['zip'];
$contact->addAddress($address);

 

$customField = new CustomField();
$customField->name = "CustomField2";
$customField->value = "CustomFieldValue";
$contact->addCustomField($customField);

 

 

Neither static strings (e.g. CustomField2) nor dynamic values ($_POST['some_value']) will POST to a new contact. The name and email will successfully POST, however.

 

https://gist.github.com/dsjellz/5562021 this was the only help I could find and it does not work. Please advise.

3 REPLIES 3
Member

Hello,

 

I wanted to post here to let you know that I am researching this issue for you to find an answer to your question. Would it be possible to include the code where you are actually submitting the contact to Constant Contact? If there is sensitive code you are concerned about sharing here in the forums, please feel free to send us an email to webservices@constantcontact.com with the details.

 

I will follow up here tomorrow with my findings for you.

 

Sincerely,

Elijah G.

API Support Specialist

Elijah G.
API Support Engineer
Occasional Participant

Any follow up on this? I'm having the same trouble, doesn't seem to be documented anywhere.

Hello,

 

I just personally tested the sample code provided above and was successfully able to add a contact with a custom field and an address. Is it possible to decribe the specifics of what is happening for you, and potentially a sample of the code that is being used to create the contact?

 

Here is a sample of what works for me:

    
    $contact = new Contact();
    $contact->addEmail("example@email.com");
    $contact->addList("LISTID");
    $contact->last_name = "last";
    
    $address = new Address();
    $address->address_type = "UNKNOWN";
    $address->line1 = "Street Name";
    $address->city = "City";
    $address->state_code = "MA";
    $address->postal_code = "01720";
    $contact->addAddress($address);
    
    $customField = new CustomField();
    $customField->name = "CustomField2";
    $customField->value = "CustomFieldValue";
    $contact->addCustomField($customField);
    $cc->addContact(ACCESS_TOKEN, $contact);

 

Best Regards,

Elijah G.
API Support Engineer
Developer Portal

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

Visit Page