我们正在尝试使用那里的报告 API 从 Five9 的服务器访问数据。我们在下面编写了代码,但没有得到任何结果。在我看来,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);
?>
示例 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>
最佳答案
看起来您的问题是您在soap header 中发送了base64编码的用户名/密码。它实际上需要包含在 http header 中。我的解决方案是 ruby,但希望它可以帮助你。
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
所以你的 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>[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>