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

前端之家收集整理的这篇文章主要介绍了php – Five9的API:如何使用SOAP API和基本身份验证来提取报告前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们正在尝试使用报告API从Five9的服务器访问数据.我们在下面编写了代码,但没有得到任何结果.对我来说,看起来问题是使用Authentication to Five9的服务器.请检查帮助我们了解我们如何定期为特定广告系列提取数据,并将其存储在数据仓库中.
  1. <?PHP
  2. $soapUser = "USERNAME"; // username
  3. $soapPassword = "DEMOPASSWORD"; // password
  4.  
  5. $soap_options = array( 'login' => $soapUser,'password' => $soapPassword );
  6. $auth_details = base64_encode($soapUser.":".$soapPassword);
  7.  
  8. $client = new SoapClient("https://api.five9.com/wsadmin/v2/AdminWebService?wsdl",$soap_options);
  9. $header = new SoapHeader("https://api.five9.com/wsadmin/v2/AdminWebService/getCallLogReport","authentication","Basic $auth_details");
  10. //echo "Response:\n" . $client->__getLastResponse() . "\n";
  11. $client->__setSoapHeaders($header);
  12.  
  13. $xml_data = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://service.admin.ws.five9.com/v2/AdminWebService/getCallLogReport">
  14. <soapenv:Header/>
  15. <soapenv:Body>
  16. <v2:getCallLogReport>
  17. <campaigns>Campaign1</campaigns>
  18. </v2:getCallLogReport>
  19. </soapenv:Body>
  20. </soapenv:Envelope>';
  21.  
  22. echo $result = $client->getCallLogReport($xml_data,"https://api.five9.com/wsadmin/v2/AdminWebService?wsdl","https://api.five9.com/wsadmin/v2/AdminWebService/getCallLogReport",0);
  23.  
  24.  
  25. ?>

示例XML

  1. <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://service.admin.ws.five9.com/v2/">
  2. <soapenv:Header/>
  3. <soapenv:Body>
  4. <v2:getCallLogReport>
  5. <!--Optional:-->
  6. <time>
  7. <!--Optional:-->
  8. <end>?</end>
  9. <!--Optional:-->
  10. <start>?</start>
  11. </time>
  12. <!--Optional:-->
  13. <criteria>
  14. <!--Optional:-->
  15. <ANI>?</ANI>
  16. <!--Zero or more repetitions:-->
  17. <agents>?</agents>
  18. <!--Zero or more repetitions:-->
  19. <callTypes>?</callTypes>
  20. <!--Zero or more repetitions:-->
  21. <campaigns>?</campaigns>
  22. <!--Optional:-->
  23. <DNIS>?</DNIS>
  24. <!--Zero or more repetitions:-->
  25. <dispositions>?</dispositions>
  26. <!--Zero or more repetitions:-->
  27. <lists>?</lists>
  28. <!--Zero or more repetitions:-->
  29. <skillGroups>?</skillGroups>
  30. </criteria>
  31. </v2:getCallLogReport>
  32. </soapenv:Body>
  33. </soapenv:Envelope>
看起来您的问题是您在soap标头中发送base64编码的用户名/密码.它实际上需要包含在http标头中.我的解决方案是ruby,但希望它可以帮助你.
  1. soap_client = Savon.client(
  2. 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
  3. )
  4.  
  5. message = {
  6. "lookupCriteria" => {
  7. "criteria" => {
  8. "field" => "email_address","value" => "something@example.com"
  9. }
  10. }
  11. }
  12.  
  13. response = soap_client.call(:getContactRecords,message: message)
  14. p response.body

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

  1. SOAP request: https://api.five9.com/wsadmin/AdminWebService/
  2. Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==,SOAPAction: "getContactRecords",Content-Type: text/xml;charset=UTF-8,Content-Length: 471
  3.  
  4. <?xml version="1.0" encoding="UTF-8"?>
  5. <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/">
  6. <soapenv:Body>
  7. <ser:getContactRecords>
  8. <lookupCriteria>
  9. <criteria>
  10. <field>email_address</field>
  11. <value>something@example.com</value>
  12. </criteria>
  13. </lookupCriteria>
  14. </ser:getContactRecords>
  15. </soapenv:Body>
  16. </soapenv:Envelope>
  17.  
  18. HTTPI POST request to api.five9.com (httpclient)
  19. SOAP response (status 200)
  20.  
  21. <env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/'>
  22. <env:Header></env:Header>
  23. <env:Body>
  24. <ns2:getContactRecordsResponse xmlns:ns2="http://service.admin.ws.five9.com/" xmlns:ns3="http://service.admin.ws.five9.com/v1/">
  25. <return>
  26. <fields>number1</fields>
  27. <fields>email_address</fields>
  28. <records>
  29. <values>
  30. <data>5555555555</data>
  31. <data>something@example.com</data>
  32. </values>
  33. </records>
  34. </return>
  35. </ns2:getContactRecordsResponse>
  36. </env:Body>
  37. </env:Envelope>

猜你在找的PHP相关文章