Reputation: 8463
I had tried to connect Five9 and to send a record to Five9 inorder to add in the list
My Codes is below
$soapUser = "[email protected]"; // username
$soapPassword = "password"; // password
$soap_options = array( 'login' => $soapUser, 'password' => $soapPassword );
$auth_details = base64_encode($soapUser.":".$soapPassword);
$client = new SoapClient("https://api.five9.com/wsadmin/v2/AdminWebService?wsdl", $soap_options);
$header = new SoapHeader("https://api.five9.com/wsadmin/v2/AdminWebService/AddRecordToList", "authentication", "Basic $auth_details");
//echo "Response:\n" . $client->__getLastResponse() . "\n";
$client->__setSoapHeaders($header);
$xml_data = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:ser="http://service.admin.ws.five9.com/">
<soapenv:Header />
<soapenv:Body>
<ser:addRecordToList>
<listName>some_list_name</listName>
<listUpdateSettings>
<fieldsMapping>
<columnNumber>1</columnNumber>
<fieldName>number1</fieldName>
<key>true</key>
</fieldsMapping>
<fieldsMapping>
<columnNumber>2</columnNumber>
<fieldName>first_name</fieldName>
<key>false</key>
</fieldsMapping>
<fieldsMapping>
<columnNumber>3</columnNumber>
<fieldName>last_name</fieldName>
<key>false</key>
</fieldsMapping>
<reportEmail>[email protected]</reportEmail>
<separator>,</separator>
<skipHeaderLine>false</skipHeaderLine>
<callNowMode>ANY</callNowMode>
<cleanListBeforeUpdate>false</cleanListBeforeUpdate>
<crmAddMode>ADD_NEW</crmAddMode>
<crmUpdateMode>UPDATE_FIRST</crmUpdateMode>
<listAddMode>ADD_FIRST</listAddMode>
</listUpdateSettings>
<record>
<fields>5551208111</fields>
<fields>John</fields>
<fields>Smith</fields>
</record>
</ser:addRecordToList>
</soapenv:Body>
</soapenv:Envelope>';
echo $client->__doRequest($xml_data, "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl", "https://api.five9.com/wsadmin/v2/AdminWebService/AddRecordToList",0);
Please guide me to connect five9 and to send Record to Five9 in order to add in the list.
Upvotes: 1
Views: 3640
Reputation: 614
The Problem is because of even if you set the Header i.e. User Name
and password
to Header record. That gets incorporate in XML Data
which is send to WebService in doRequest
.
Solutions
1. If you want to use doRequest
, You need to send the XML
with proper Header node ie. with Username
and password
in authentication node.
2. Instead of doRequest
, use __soapCall
, using $client
object with function addRecordToList
.
You can get more information here.
Upvotes: 0
Reputation: 631
hey this question is old but I managed to put a class together that will add records to a list just edit your field names as needed. It uses AddRecordtoList();
you can view there documentation here
class five9{
//the fields mapped to five9
//initialize and empty array so there are no errors with array_push
private static $listUpdateSettings = array("fieldsMapping" => array());
//maps field to five9 columns
protected function mapField($index, $field, $key = false){
//map the field to five9. Index must start at 1 not 0
//mapping fields this way allows flexibility in which order the parameter has its keys
array_push( self::$listUpdateSettings["fieldsMapping"], array( "columnNumber" => $index + 1, "fieldName" => $field, "key" => $key ));
}
//returns data array after being scrubbed
protected function checkArray( array $lead){
//data sent to five9
$data = array();
//counter
$i = 0;
//five9 requires the $field names outlined below
foreach($lead as $field => $value){
//make sure first_name is 3 characters or more
if( ($field == 'first_name' && strlen($field) > 3)){
//add field to array
$data[$i] = $value;
//map the field in five9
self::mapField($i, $field);
}
//make sure last_name is 3 characters or more
if($field == 'last_name' && strlen($field) > 3 ){
//add field to array
$data[$i] = $value;
//map the field in five9
self::mapField($i, $field);
}
//if the field is a phone number
if( $field == 'number1' ){
//add field to array
$data[$i] = preg_replace("/[^0-9]/", "", $value);
//map the field in five9
//this was they key for my instance
self::mapField($i, $field, true);
}
//if the field is a phone number
if( $field == 'number2' ){
//add field to array
$data[$i] = preg_replace("/[^0-9]/", "", $value);
//setup column mapping in five9
self::mapField($i, $field);
}
//make sure the state is only two characters
if($field == 'state' && strlen($value) <= 2){
//add field to array
$data[$i] = $value;
//setup column mapping in five9
self::mapField($i, $field);
}
//make sure the state is only two characters
if($field == 'zip' && strlen($value) <= 5){
//add field to array
$data[$i] = $value;
//setup column mapping in five9
self::mapField($i, $field);
}
//make sure memberid is an int
if($field == 'member_id' && is_numeric($value)){
//add field to array
$data[$i] = $value;
//setup column mapping in five9
self::mapField($i, $field);
}
//increase the counter
$i++;
}
//return the data array that is constructed
return $data;
}
static function sendToFive9(array $lead ){
//the conctructed array
$data = self::checkArray($lead);
//if the fields sent are all correct both arrays are the same size
if(sizeof($lead) === sizeof($data) ){
// Import the WSDL and authenticate the user.-----------------------------
$wsdl_five9 = "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl&user=$username";
//try to authenticate with five9
try{
$soap_options = array( 'login' => '$username',
'password' => '$password',
'trace' => true );
$client_five9 = new SoapClient( $wsdl_five9 , $soap_options );
}//if errors occur add the message to the response array
catch (Exception $e){
$error_message = $e->getMessage();
$response['error'] = $error_message;
}
//settings required by five9
self::$listUpdateSettings["skipHeaderLine"] = false;
self::$listUpdateSettings["cleanListBeforeUpdate"] = false;
self::$listUpdateSettings["crmAddMode"] = 'ADD_NEW';
self::$listUpdateSettings["crmUpdateMode"] = 'UPDATE_SOLE_MATCHES';
self::$listUpdateSettings["listAddMode"] = 'ADD_IF_SOLE_CRM_MATCH';
//the default list for all new leads
$list = "test";
//prepare the query used to add the record to five9
$query = array ( 'listName' => "$list",
'listUpdateSettings' => self::$listUpdateSettings,
'record' => $data );
//get the result from running the query
//this will return an object
$result = $client_five9->AddRecordToList($query);
//get the array of variables within the results object
$variables = get_object_vars($result);
//get the array of varaibles within the return array of objects
$resp = get_object_vars($variables['return']);
//if there was an error adding the record
if($resp['failureMessage'] != ""){
$response['errors'] = $resp['failureMessage'];
}
//if it was successful either adding or updating
if($resp['crmRecordsUpdated'] == 1 || $resp['crmRecordsInserted'] == 1){
$response['success'] = true;
//reset the settings array so this class can be looped without passing the lists back and forth
self::$listUpdateSettings = array("fieldsMapping" => array());
}
}//end if
else{
//return the differences in the arrays usually caused due to improper names
$reponse["errors"] = array_diff($lead, $data);
}
return $response;
}//end function
}
Upvotes: 0
Reputation: 6275
I wanted to build upon @Jesse Q's excellent answer with something that worked for me....
$auth = array("login" => "your login",
"password" => "your password");
$wsdl = "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl";
$soap = new SoapClient($wsdl, $auth);
$fields = array("number1" => "555-666-7777",
"first_name" => "John",
"last_name" => "Doe",
"street" => "",
"city" => "",
"state" => "",
"zip" => "");
// these are the columns we're sending so Five9 knows what we're sending
$columns = array();
$keys = array_keys($fields);
for ($x = 0; $x < count($fields); ++$x)
$columns[$x] = array("columnNumber" => $x + 1,
"fieldName" => $keys[$x],
"key" => "false");
// assemble the settings...
$settings = array("fieldsMapping" => $columns,
"cleanListBeforeUpdate" => 0,
"crmAddMode" => "ADD_NEW",
"crmUpdateMode" => "UPDATE_FIRST",
"listAddMode" => "ADD_FIRST",
"skipHeaderLine" => "false");
// assemble the request...
$record = array_values($fields);
$params = array("listName" => $list,
"listUpdateSettings" => $settings,
"record" => $record);
$response = $soap->addRecordToList($params);
You could even perform some check for the list's existence and add it, should it not exist.
$list_lookup = $soap->getListsInfo(array("listNamePattern" => $list));
if (!($list_lookup->return && $list_lookup->return->name))
$soap->createList(array("listName" => $list));
Upvotes: 2
Reputation: 1671
You can use the following PHP code to insert a record into a Five9 dialing list. I realize this question is nearly a year old, but since it hasn't been answered and there is a distinct lack of PHP examples for the Five9 API, I figured this is still relevant.
$soap = null;
$wsdl = "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl";
$user = "YourLoginID";
$pass = "YourPassword";
$soap_options = array('login' => $user, 'password' => $pass );
$soap = new SoapClient($wsdl, $soap_options);
/* Field Mapping */
$arryFields = array();
$arryFields[0] = array("columnNumber"=>1,"fieldName" => "number1", "key" => "false");
$arryFields[1] = array("columnNumber"=>2,"fieldName" => "first_name", "key" => "false");
$arryFields[2] = array("columnNumber"=>3,"fieldName" => "last_name", "key" => "false");
$arryFields[3] = array("columnNumber"=>4,"fieldName" => "street", "key" => "false");
$arryFields[4] = array("columnNumber"=>5,"fieldName" => "city", "key" => "false");
$arryFields[5] = array("columnNumber"=>6,"fieldName" => "state", "key" => "false");
$arryFields[6] = array("columnNumber"=>7,"fieldName" => "zip", "key" => "false");
//$arrySettings['callNowColumnNumber'] = 0;
$arrySettings['cleanListBeforeUpdate'] = 0;
$arrySettings['crmAddMode'] = "ADD_NEW"; //DONT_ADD or ADD_NEW
$arrySettings['crmUpdateMode'] = "UPDATE_FIRST";
$arrySettings['listAddMode'] = "ADD_FIRST";
$arryValues[0] = "9515551212";
$arryValues[1] = "FirstName";
$arryValues[2] = "LastName";
$arryValues[3] = "123 Main St.";
$arryValues[4] = "Corona";
$arryValues[5] = "CA";
$arryValues[6] = "92881";
$arryParams['parameters']['listName'] = "Z-outbound-test";
$arryParams['parameters']['listUpdateSettings'] = $arrySettings;
$arryParams['parameters']['record'] = $arryValues;
try {
$result = $soap->__soapCall("addRecordToList", $arryParams);
} catch (SoapFault $e) {
/* your error handling */
}
Upvotes: 3