I'm using http://api.stickystreet.com/ API for recording some customer data fetching it from a XML file using php. As mentioned in the docs I'm using the function provided by them of curl as below:
// Data posting to SS API using CURL
function submit_cURL ($data) {
// initialize curl handle:
$ch = curl_init();
// set url to post to:
curl_setopt($ch, CURLOPT_URL, 'https://api.clienttoolbox.com' );
// return into a variable instead on on-screen:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// Set timeout, in seconds:
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// add XML data here:
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// turn off verification of SSL for testing:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
// Workaround for certain Virtual Hosting hosts:
// curl_setopt ($ch, CURLOPT_PROXY,"http://");
// Send query to server:
$result = curl_exec($ch);
curl_close ($ch);
// Create a SimpleXML object from the result and return it.
$parsed_result = new SimpleXMLElement($result);
return $parsed_result;
}
I search for a customer and if a customer using the above curl function call and if a customer matches I then try to create the customer. It all happends in a foreach loop of XML data with Customers.
The issue here is that the it only checks for one customer and creates only one as per my below logic:
Search Customer:
// Preparing the data to search the customer in SS API
$data['user_id'] = $ss_user_id;
$data['user_password'] = $ss_api_key;
$data['type'] = 'customer_search';
$data['account_id'] = $ss_account_id;
$data['email'] = $uniqueID;
$data['exact_match'] = 'sensitive';
// looping through the xml file data
foreach ($simplexml->StayInfos->StayInfo as $StayInfo)
{
$customer_search = submit_cURL ($data);
if ($customer_search['status']=='no_match') {
// Records the Customer
}
else
{
// if matches then update the customer info
$customer_update = submit_cURL ($data);
}
}