mardi 27 janvier 2015

Insightly CRM API - Add Contact with data from WordPress form


I've been able to set up the data for submission to Insightly CRM, but I've never used an API before. I don't know if this is set up right, and I don't know how to tell if there's been an error since no error is displayed. I'm using the insightly-php from github: http://ift.tt/1CvEHKe


I am trying to add a contact into my Insightly account using data from a form. Here's the AJAX:



$(".insightly-wrapper form").submit(function(){
var processURL = (insightlyLocalized.insightlyURL)+'insightly-process.php';
$.post(
processURL,
$(this).serialize(),
function(data){
console.log('form submitted');
}
);
});


This code displays the 'form submitted' in the inspector console, so I know that part is working at least. But how do I submit the data correctly? I have created a plugin to record the names of the corresponding fields, so I get those values and get the POST data accordingly.


I've tried echoing values within this file, but no values display. Here's the PHP code I have so far:



$formfields = get_option('insightly_data');
$insightly_api = $formfields['insightly_api'];

$wp_firstname_name = $formfields['insightly_firstname'];
...(continue variable assigning)...

$wp_firstname_value = $_POST["$wp_firstname_name"];
...(continue variable assigning)...

require("insightly.php");
$i = new Insightly($insightly_api);

$contact_data = new stdClass();
$contact_data->CONTACT_ID = 0;
$contact_data->FIRST_NAME = $wp_firstname_value;
$contact_data->LAST_NAME = $wp_lastname_value;
$contact_data->CONTACT_FIELD_1 = $wp_field1_value;
$contact_data->CONTACT_FIELD_2 = $wp_field2_value;
$contact_data->CONTACT_FIELD_3 = $wp_field3_value;
$contact_data->CONTACT_FIELD_4 = $wp_field4_value;
$contact_data->CONTACT_FIELD_5 = $wp_field5_value;
$contact_data->ADDRESSES = array(
(object)array(
"ADDRESS_ID" => 1,
"ADDRESS_TYPE" => "Home",
"STREET" => $wp_street_value,
"CITY" => $wp_city_value,
"STATE" => $wp_state_value,
"POSTCODE" => $wp_zip_value,
"COUNTRY" => "US"
)
);
$contact_data->CONTACT_INFOS = array(
(object)array(
"CONTACT_INFO_ID" => 1,
"TYPE" => "Phone",
"DETAIL" => $wp_phone_value
),
(object)array(
"CONTACT_INFO_ID" => 1,
"TYPE" => "Email",
"DETAIL" => $wp_email_value
)
);

$contact_update = $i->addContact($contact_data);


This code is in a file inside my main theme. I'm not even sure where to go from here, and I couldn't find an example of the php needed for an add contact.





Aucun commentaire:

Enregistrer un commentaire