1

I had tried to connect Five9 and to send a record to Five9 inorder to add in the list

My Codes is below

    $soapUser = "test@sample.com";  //  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>name@example.com</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.

4

4 回答 4

3

您可以使用以下 PHP 代码将记录插入到 Five9 拨号列表中。我意识到这个问题已经有将近一年的历史了,但由于它还没有得到回答,而且 Five9 API 的 PHP 示例明显缺乏,我认为这仍然是相关的。

$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 */
}
于 2013-07-01T21:34:40.257 回答
2

我想在@Jesse Q 的优秀答案的基础上,用对我有用的东西......

$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);

如果列表不存在,您甚至可以执行一些检查并添加它。

$list_lookup = $soap->getListsInfo(array("listNamePattern" => $list));
if (!($list_lookup->return && $list_lookup->return->name))
  $soap->createList(array("listName" => $list));
于 2014-04-01T21:50:40.633 回答
0

问题是因为即使您设置了 Header ieUser NamepasswordHeader 记录。这被合并到XML Data其中发送到WebService in doRequest

解决方案
1. 如果你想使用doRequest,你需要发送XML带有正确的 Header 节点,即。withUsernamepasswordin 认证节点。
2. 而不是doRequest,使用__soapCall,使用$client带有功能的对象addRecordToList

您可以在此处获得更多信息。

于 2012-07-30T07:06:07.947 回答
0

嘿,这个问题很老,但我设法将一个类放在一起,将记录添加到列表中,只需根据需要编辑您的字段名称。它使用 AddRecordtoList();

你可以在这里查看文档

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

}
于 2017-10-02T21:15:32.210 回答