如何将记录发送到五.9

时间:2012-07-26 08:19:26

标签: php soap ivr

我曾尝试连接Five9并将记录发送到Five9以便添加到列表中

我的代码在下面

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

请引导我连接five9并将Record发送到Five9以便添加到列表中。

4 个答案:

答案 0 :(得分: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 */
}

答案 1 :(得分:1)

我希望以@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));

答案 2 :(得分:0)

问题是因为即使您将标题设置为User Namepassword到标题记录。这将合并到XML Data中,并发送给WebService in doRequest

<强>解决方案
1.如果要使用doRequest,则需要使用正确的标头节点发送XML,即。在身份验证节点中使用Usernamepassword 2.使用doRequest,而不是__soapCall,使用$client对象与函数addRecordToList

您可以获得更多信息here

答案 3 :(得分:0)

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

您可以在那里查看文档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

}