This part works:
$contact = new Contact; $contact->addEmail($email); $contact->addList($row->cc_list_id); $cc->addContact($token, $contact, true);
However, as soon as I add a custom field it fails with this cryptic message:
{"error_key":"http.status.bad_request","error_message":"Bad request."}
This is the portion with custom fields:
$contact = Contact::create($merge_vars); $contact->addEmail($email); $contact->addList($row->cc_list_id); $cc->addContact($token, $contact, true);
$merge_vars looks like this:
array(9) { ["addresses"]=> array(1) { [0]=> array(9) { ["line1"]=> string(0) "" ["line2"]=> string(0) "" ["line3"]=> string(0) "" ["city"]=> string(0) "" ["state_code"]=> string(0) "" ["state"]=> string(0) "" ["country_code"]=> string(0) "" ["postal_code"]=> string(0) "" ["sub_postal_code"]=> string(0) "" } } ["first_name"]=> string(0) "" ["last_name"]=> string(0) "" ["middle_name"]=> string(0) "" ["home_phone"]=> string(0) "" ["company_name"]=> string(0) "" ["job_title"]=> string(0) "" ["work_phone"]=> string(0) "" ["custom_fields"]=> array(15) { [0]=> array(2) { ["name"]=> string(12) "CustomField1" ["value"]=> string(0) "" } [1]=> array(2) { ["name"]=> string(12) "CustomField2" ["value"]=> string(0) "" } [2]=> array(2) { ["name"]=> string(12) "CustomField3" ["value"]=> string(0) "" } [3]=> array(2) { ["name"]=> string(12) "CustomField4" ["value"]=> string(0) "" } [4]=> array(2) { ["name"]=> string(12) "CustomField5" ["value"]=> string(0) "" } [5]=> array(2) { ["name"]=> string(12) "CustomField6" ["value"]=> string(0) "" } [6]=> array(2) { ["name"]=> string(12) "CustomField7" ["value"]=> string(0) "" } [7]=> array(2) { ["name"]=> string(12) "CustomField8" ["value"]=> string(0) "" } [8]=> array(2) { ["name"]=> string(12) "CustomField9" ["value"]=> string(0) "" } [9]=> array(2) { ["name"]=> string(13) "CustomField10" ["value"]=> string(0) "" } [10]=> array(2) { ["name"]=> string(13) "CustomField11" ["value"]=> string(0) "" } [11]=> array(2) { ["name"]=> string(13) "CustomField12" ["value"]=> string(0) "" } [12]=> array(2) { ["name"]=> string(13) "CustomField13" ["value"]=> string(0) "" } [13]=> array(2) { ["name"]=> string(13) "CustomField14" ["value"]=> string(0) "" } [14]=> array(2) { ["name"]=> string(13) "CustomField15" ["value"]=> string(0) "" } } }
The resulting JSON looks like:
{"id":null,"status":null,"first_name":"","last_name":"","confirmed":null,"source":null,"email_addresses":[{"id":null,"status":null,"confirm_status":null,"opt_in_source":null,"opt_in_date":null,"opt_out_date":null,"email_address":"octavian@test.com"}],"prefix_name":null,"job_title":"","addresses":[{"id":null,"line1":"","line2":"","line3":"","city":"","address_type":null,"state_code":"","state":"","country_code":"","postal_code":"","sub_postal_code":""}],"notes":[],"company_name":"","home_phone":"","work_phone":"","cell_phone":null,"fax":null,"custom_fields":[{"name":"CustomField1","value":""},{"name":"CustomField2","value":""},{"name":"CustomField3","value":""},{"name":"CustomField4","value":""},{"name":"CustomField5","value":""},{"name":"CustomField6","value":""},{"name":"CustomField7","value":""},{"name":"CustomField8","value":""},{"name":"CustomField9","value":""},{"name":"CustomField10","value":""},{"name":"CustomField11","value":""},{"name":"CustomField12","value":""},{"name":"CustomField13","value":""},{"name":"CustomField14","value":""},{"name":"CustomField15","value":""}],"lists":[{"id":"1234567890","name":null,"status":null,"contact_count":null}],"created_date":null,"modified_date":null,"source_details":null}
I've edited my email address and the list ID (both are correct nonetheless since they work if I don't add the other fields). This JSON is produced by:
$contact->toJson();
My questions now are:
Hi Octavian,
UPDATE: Upon looking at the error you were getting, the issue is more likely that you need to set the address_type to be either "PERSONAL" or "BUSINESS." Setting that value should solve your issue. You have the value as null right now.
Previous response:
You are setting the custom field names yourself, right?
Try setting the custom field names to be in the format "custom_field_n" where n=1=15. Below are two code samples for the custom field portion, and at least one of them should work. Sorry for the ambiguity here, but I'm prioritizing a quick response to you (I'm not sure whether label is still required).
$contact->custom_fields = array( array('name' => 'custom_field_1', 'value' => 'value 1'), array('name' => 'custom_field_2', 'value' => 'value 2') );
$contact->custom_fields = array( array('label' => 'Custom Field 1', 'name' => 'custom_field_1', 'value' => 'value 1'), array('label' => 'Custom Field 2', 'name' => 'custom_field_2', 'value' => 'value 2') );
Let me know how that goes.
Best Regards,
Shannon Wallace
Partner API Support Engineer
The holidays have come and gone. For many seasonal businesses, this means the rush of shoppers has decreased as well. Instead of turning off the lights and waiting for spring, make your email marketi...
See Article