Trying to add State to Contact via form. Get Error below. Other fields like "company_name" and "job_title" work fine. Thanks!
Error Creating Contact
Array ( [0] => Array ( [error_key] => json.field.invalid [error_message] => #/state: Property was found but is not permitted at this location. ) )
Solved! Go to Solution.
Yes, PHP SDK, sorry forgot to mention that. Your response helped solve this issue. There was one additional bit I needed to add in the AutoLoader include first:
use Ctct\Components\Contacts\Address;
Then, the final result for my successful code was:
$contact = new Contact();
$contact->addEmail($_POST['Email']);
$contact->addList("999999999"); // I was hardcoding the List ID in mine so I replaced with 9s for demo.
$contact->first_name = $_POST['Name'];
$contact->company_name = $_POST['company_name'];
$contact->job_title = $_POST['Title'];
$contact->work_phone = $_POST['Phone'];
$state = $_POST['State'];
$contact->addAddress(Address::create( array("address_type"=>"BUSINESS","state"=>$state)));
THANK YOU!
Hi - In order for me to investigate and understand what's happening with the issue you're experiencing, please send along the JSON payload you're using to create the contact.
Thanks,
Hi,
Are you using our PHP SDK? Whether you are or not, this issue probably stems from the fact that address infromation is stored inside arrays, whereas most of the other contact information (like name and company) are stored NOT in arrays). If you're using our PHP SDK, below is a quick example of how to add the state. I would avoid the state_code field and use the 'state' field, since the user interface when you login to the account uses the state field to fill in the information.
//hard coding address values for simple testing $street = "line 1 address"; $city = "city"; $state = "California"; $zip = "95758"; $contact = new Contact(); //only for new contacts $contact->addEmail($_POST['email']); $contact->addList($_POST['list']); $contact->first_name = $_POST['first_name']; $contact->last_name = $_POST['last_name']; $contact->addAddress(Address::create( array("address_type"=>"BUSINESS","line1"=>$street,"city"=>$city,"state"=>$state,"postal_code"=>$zip))); //change the above address fields to take information from user input
If you're not using the PHP SDK, you can take a look at our contact documentation pages to see how the state and other physical address fields should be wrapped inside a JSON array.
Best Regards,
Shannon Wallace
Partner API Support Engineer
Yes, PHP SDK, sorry forgot to mention that. Your response helped solve this issue. There was one additional bit I needed to add in the AutoLoader include first:
use Ctct\Components\Contacts\Address;
Then, the final result for my successful code was:
$contact = new Contact();
$contact->addEmail($_POST['Email']);
$contact->addList("999999999"); // I was hardcoding the List ID in mine so I replaced with 9s for demo.
$contact->first_name = $_POST['Name'];
$contact->company_name = $_POST['company_name'];
$contact->job_title = $_POST['Title'];
$contact->work_phone = $_POST['Phone'];
$state = $_POST['State'];
$contact->addAddress(Address::create( array("address_type"=>"BUSINESS","state"=>$state)));
THANK YOU!