2012-11-24 28 views
7

Chúng tôi đang cố gắng truy cập dữ liệu từ máy chủ của Five9 bằng cách sử dụng API báo cáo đó. Chúng tôi đã viết mã dưới đây nhưng không nhận được bất kỳ kết quả nào. Đối với tôi, có vẻ như vấn đề là với máy chủ của Authentication to Five9. Vui lòng kiểm tra giúp chúng tôi hiểu cách chúng tôi có thể lấy dữ liệu cho một chiến dịch cụ thể trong khoảng thời gian thường xuyên và lưu trữ dữ liệu đó trong Kho dữ liệu.API của Five9: Cách kéo báo cáo bằng API SOAP và Xác thực cơ bản

<?php 
$soapUser = "USERNAME"; // username 
$soapPassword = "DEMOPASSWORD"; // 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/getCallLogReport", "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:v2="http://service.admin.ws.five9.com/v2/AdminWebService/getCallLogReport"> 
<soapenv:Header/> 
<soapenv:Body> 
    <v2:getCallLogReport> 
     <campaigns>Campaign1</campaigns> 
    </v2:getCallLogReport> 
</soapenv:Body> 
</soapenv:Envelope>'; 

echo $result = $client->getCallLogReport($xml_data, "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl", "https://api.five9.com/wsadmin/v2/AdminWebService/getCallLogReport",0); 


?> 

mẫu XML

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://service.admin.ws.five9.com/v2/"> 
<soapenv:Header/> 
<soapenv:Body> 
    <v2:getCallLogReport> 
    <!--Optional:--> 
    <time> 
     <!--Optional:--> 
     <end>?</end> 
     <!--Optional:--> 
     <start>?</start> 
    </time> 
    <!--Optional:--> 
    <criteria> 
     <!--Optional:--> 
     <ANI>?</ANI> 
     <!--Zero or more repetitions:--> 
     <agents>?</agents> 
     <!--Zero or more repetitions:--> 
     <callTypes>?</callTypes> 
     <!--Zero or more repetitions:--> 
     <campaigns>?</campaigns> 
     <!--Optional:--> 
     <DNIS>?</DNIS> 
     <!--Zero or more repetitions:--> 
     <dispositions>?</dispositions> 
     <!--Zero or more repetitions:--> 
     <lists>?</lists> 
     <!--Zero or more repetitions:--> 
     <skillGroups>?</skillGroups> 
    </criteria> 
    </v2:getCallLogReport> 
    </soapenv:Body> 
</soapenv:Envelope> 

Trả lời

4

Dường như vấn đề của bạn là bạn gửi base64 của bạn được mã hóa tên người dùng/mật khẩu trong tiêu đề xà phòng. Nó thực sự cần phải được bao gồm trong tiêu đề http. Giải pháp của tôi là ruby ​​nhưng hy vọng nó có thể giúp bạn.

soap_client = Savon.client(
    endpoint: "https://api.five9.com/wsadmin/AdminWebService/", 
    namespace: "http://service.admin.ws.five9.com/", 
    headers: { "Authorization" => "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" }, 
    env_namespace: :soapenv, 
    namespace_identifier: :ser, 
    ssl_verify_mode: :none 
) 

message = { 
    "lookupCriteria" => { 
"criteria" => { 
     "field" => "email_address", 
     "value" => "[email protected]" 
    } 
    } 
} 

response = soap_client.call(:getContactRecords, message: message) 
p response.body 

Vì vậy, XML của bạn sẽ kết thúc như thế này.

SOAP request: https://api.five9.com/wsadmin/AdminWebService/ 
Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==, SOAPAction: "getContactRecords", 
Content-Type: text/xml;charset=UTF-8, Content-Length: 471 

<?xml version="1.0" encoding="UTF-8"?> 
<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ser="http://service.admin.ws.five9.com/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soapenv:Body> 
    <ser:getContactRecords> 
     <lookupCriteria> 
     <criteria> 
      <field>email_address</field> 
      <value>[email protected]</value> 
     </criteria> 
     </lookupCriteria> 
    </ser:getContactRecords> 
    </soapenv:Body> 
</soapenv:Envelope> 

HTTPI POST request to api.five9.com (httpclient) 
SOAP response (status 200) 

<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'> 
    <env:Header></env:Header> 
    <env:Body> 
    <ns2:getContactRecordsResponse xmlns:ns2="http://service.admin.ws.five9.com/" xmlns:ns3="http://service.admin.ws.five9.com/v1/"> 
     <return> 
     <fields>number1</fields> 
     <fields>email_address</fields> 
     <records> 
      <values> 
      <data>5555555555</data> 
      <data>[email protected]</data> 
      </values> 
     </records> 
     </return> 
    </ns2:getContactRecordsResponse> 
    </env:Body> 
</env:Envelope> 
6

Tôi biết đây là câu hỏi cũ, nhưng gần đây chúng tôi đã chuyển sang sử dụng Five9 và tôi không thể tìm thấy bất kỳ ví dụ PHP nào để làm việc. Phần sau minh họa cách kết nối bằng cách sử dụng thông tin đăng nhập chuẩn và thực thi danh sách cuộc gọi. Tôi đã bao gồm toàn bộ cấu trúc tiêu chí lựa chọn (đã nhận xét) để bạn tham khảo. Nếu bạn bao gồm thuộc tính lựa chọn, bạn phải chỉ định tiêu chí tương ứng.

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

/* create the callLogReportCriteria data selection structure */ 
$arryParams['time'] = array("start" => "2013-05-05T00:00:01", 
          "end" => "2013-05-05T09:00:00"); 
$arryParams['criteria'] = array("callTypes" => array("INBOUND","OUTBOUND")); 

/************ Entire Structure for selection criteria *************/ 
/*$arryParams['criteria'] = array("ANI" => "6178752803", 
           "Agents" => "", 
           "callTypes" => array("INBOUND","OUTBOUND"), 
           "campaigns" => "", 
           "dispositions" => "", 
           "Lists" => "", 
           "skillGroups" => "" 
           );*/ 

$result = $soap->getCallLogReport($arryParams); 

if(isset($result->return->records)) { 
    /* you have records returned */ 
    $objRecords = $result->return->records; 

    for($i=0 ; $i < sizeof($objRecords) ; $i++) { 
     /* do your processing */ 
     printf("ANI: %s<br />", $objRecords[$i]->values->data[3]); //4th element has ANI 
    } 

} 

Một số dòng mã nhất định có thể được kết hợp, nhưng vì mục đích dễ hiểu, tôi đã phá vỡ chúng. Bạn cũng sẽ muốn sử dụng một try/catch xung quanh cuộc gọi SOAP thực tế để xử lý lỗi.

Hy vọng điều này sẽ giúp rút ngắn đường cong học tập của ai đó. Tôi biết tôi đã có thể yêu thích đã có một tháng trước đây !!

1

@JesseQ ví dụ tuyệt vời! Giúp tôi một tấn. Đây là cách tôi thiết lập nó để chạy bất kỳ báo cáo Five9 nào trong kho vũ khí của họ, kể cả những bản thân bạn tự tạo ra. Đối với báo cáo tùy chỉnh, bạn sẽ cần phải tạo một thư mục/báo cáo mới và đặt nó trong phần "Báo cáo tùy chỉnh" trên cổng web Five9. Hi vọng điêu nay co ich.

MySQL Database Connection (dbConnect.php)

<?php 
    $mysqli = new mysqli("your db's IP address", "your db user", "your db password", "your db"); 
    if ($mysqli->connect_error) { 
     die('Connect Error: (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error); 
    } 
?> 

Cơ sở dữ liệu Five9/MySQL nhập

<?php 
    require_once("../include/dbConnect.php"); 
    $startDate = new DateTime(); 
    $endDate = new DateTime(); 
    $startDate->setDate(2015, 07, 22); 
    $endDate->setDate(2015, 07, 22); 
    $five9 = "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl"; 
    $five9Credentials = array("login" => "your Five9 username", "password" => "your Five9 password"); 
    $soap = new SoapClient($five9, $five9Credentials); 
    $runReportParam["criteria"]["time"] = array("start" => $startDate->format("Y-m-d\T00:00:00"), "end" => $endDate->format("Y-m-d\T23:59:59")); 
    $runReportParam["folderName"] = "My Custom Reports"; 
    $runReportParam["reportName"] = "My First Report"; 
    $runReportResult = $soap->runReport($runReportParam); 
    if(isset($runReportResult->return)){ 
     $runReportData = $runReportResult->return; 
     $isReportRunningParam["identifier"] = $runReportData; 
     $isReportRunningParam["timeout"] = 10; 
     $isReportRunningResult = $soap->isReportRunning($isReportRunningParam); 
     if(empty($isReportRunningResult->return)){ 
      $getReportResultParam["identifier"] = $runReportData; 
      $getReportResult = $soap->getReportResult($getReportResultParam); 
      if(isset($getReportResult->return->records)){     
       $getReportResultData = $getReportResult->return->records; 
       echo "[" . date("Y-m-d h:i:s") . "] " . $runReportData . "\n"; 
       for($x = 0; $x < $xx = count($getReportResultData); $x++){ 
        $query = "REPLACE INTO MyTable(
         CallDate, CallTime, DNIS, Disposition, Zip, AreaCode, ANI) 
         VALUES (?,?,?,?,?,?,?)"; 
        $result = $mysqli->prepare($query); 
        $result->bind_param("sssssss", 
         $getReportResultData[$x]->values->data[0], 
         $getReportResultData[$x]->values->data[1], 
         $getReportResultData[$x]->values->data[2], 
         $getReportResultData[$x]->values->data[3], 
         $getReportResultData[$x]->values->data[4], 
         $getReportResultData[$x]->values->data[5], 
         $getReportResultData[$x]->values->data[6] 
        ); 
        $result->execute(); 
        $result->store_result(); 
        if ($result->error){ 
         die('Connect Error: (' . $result->errno . ') ' . $result->error); 
        } 
        echo "[" . date("Y-m-d h:i:s") . "] " . $x . "\n"; 
       } 
      } else { 
       echo "Error: " . $runReportData . " returned no data"; 
      } 
     } else { 
      echo "Error: " . $runReportData . " exceeded the report runtime limit"; 
     } 
    } else { 
     echo "Error: " . $runReportParam["reportName"] . " wasn't found"; 
    } 
    $mysqli->close(); 
?> 
Các vấn đề liên quan