Hi there,
I am trying to create a contact from an array using the PHP-SDK.
I have already got an oauth2 token and retrieved all Keap/Infusionsoft contacts, lists of custom_fields and tags. Then I can update contacts with: $infusionsoft->contacts->mock($x)->save();
and tags with $infusionsoft->contacts->find($id)->addTags(array($x));
.
But I have a problem when I try and add a new contact. I have searched the forums and docs but cannot find any answers. I am using the following code:
$template = array();
$template['addresses'] = array();
$template['anniversary'] = '';
$template['birthday'] = '';
$template['company'] = array();
$template['contact_type'] = '';
$template['custom_fields'] = array();
$template['email_addresses'] = array();
$template['family_name'] = '';
$template['fax_numbers'] = array();
$template['given_name'] = '';
$template['job_title'] = '';
$template['lead_source_id'] = '';
$template['middle_name'] = '';
$template['opt_in_reason'] = '';
$template['origin'] = array();
$template['owner_id'] = 0;
$template['phone_numbers'] = array();
$template['preferred_locale'] = 'en_GB';
$template['preferred_name'] = '';
$template['prefix'] = '';
$template['social_accounts'] = array();
$template['source_type'] = 'API';
$template['spouse_name'] = '';
$template['suffix'] = '';
$template['time_zone'] = '';
$template['website'] = '';
$query = array('email_addresses') => 'test@email.com', 'field' => 'EMAIL1');
array_merge($template, $query);
$infusionsoft->contacts()->create($query, true);
It doesnât matter if I omit the array_marge operation, the result is the same:
Client error: `POST https://api.infusionsoft.com/crm/rest/v1/contacts/?access_token=xxx` resulted in a `400 Bad Request` response: {"message":"Input could not be converted to a valid request"}
I have tried several variations but get the same error message every time:
$infusionsoft->contacts->mock($query)->save();
$infusionsoft->contacts()->create($query, true);
$infusionsoft->contacts()->create($query);
$infusionsoft->contacts->create($query, true);
$infusionsoft->contacts->create($query);
I have tried converting the array (with and without the merge as above) into JSON and using it here: createContactUsingPOST, but I get the following message:
Response Code: 0
Response Headers : "error": "no response from server"
Even if I edit the body sample from here and past it back into the contact input I get the above error again.
How am I formatting the data wrong? Any solution would be greatly appreciated.