Five9 的 API:如何使用 SOAP API 和基本身份验证提取报告 [英] Five9's API: How to pull reports using SOAP API and Basic Authentication

查看:14
本文介绍了Five9 的 API:如何使用 SOAP API 和基本身份验证提取报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正尝试使用 Five9 的服务器上的报告 API 访问数据.我们在下面编写了代码,但没有得到任何结果.在我看来,Five9 服务器的身份验证似乎有问题.请查看帮助我们了解如何定期为特定活动提取数据并将其存储在数据仓库中.

We are trying to access data from Five9's server using there reporting API. We have written code below but are not getting any results. To me it looks like issue is with the Authentication to Five9's server. Please check help us understand how we can pull data for a specific campaign on regular interval of time and store it in out Data Warehouse.

<?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 标头中发送了base64 编码的用户名/密码.它实际上需要包含在 http 标头中.我的解决方案是 ruby​​,但希望它可以帮助你.

It looks like your problem is that your sending your base64 encoded username/password in the soap header. It actually needs to be included in the http header. My solution is in ruby but hopefully it can help you out.

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

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

So your XML ends up looking like this.

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>

这篇关于Five9 的 API:如何使用 SOAP API 和基本身份验证提取报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆