Five9的API:如何使用SOAP API和基本身份验证来提取报告

Gag*_*ngh 7 php xml api soap

我们正在尝试使用报告API从Five9的服务器访问数据.我们在下面编写了代码,但没有得到任何结果.对我来说,看起来问题是使用Authentication to Five9的服务器.请检查帮助我们了解我们如何定期为特定广告系列提取数据,并将其存储在数据仓库中.

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


?>  
Run Code Online (Sandbox Code Playgroud)

示例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>
Run Code Online (Sandbox Code Playgroud)

Jes*_*e Q 6

我知道这是一个老问题,但我们最近切换到使用Five9,我找不到任何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);

/* 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
    }

}
Run Code Online (Sandbox Code Playgroud)

可以组合某些代码行,但为了便于理解,我将它们分解出来.您还需要在实际的SOAP调用周围使用try/catch来进行错误处理.

希望这有助于缩短某人的学习曲线.我知道一个月前我会喜欢这个!


Bil*_*tts 4

看来您的问题是在soap 标头中发送您的base64 编码的用户名/密码。它实际上需要包含在http标头中。我的解决方案是红宝石,但希望它可以帮助你。

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" => "something@example.com"
    }
  }
}

response = soap_client.call(:getContactRecords, message: message)
p response.body
Run Code Online (Sandbox Code Playgroud)

所以你的 XML 最终看起来像这样。

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>something@example.com</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>something@example.com</data>
          </values>
        </records>
      </return>
    </ns2:getContactRecordsResponse>
  </env:Body>
</env:Envelope>
Run Code Online (Sandbox Code Playgroud)