Five9's API: How to pull reports using SOAP API and Basic Authentication

I know this is an old question, but we recently switched to using Five9 and I couldn't find any PHP examples to work with. The following illustrates how to connect using standard credentials, and execute the call list. I've included the entire selection criteria structure (commented out) for your reference. If you include a selection property, you must specify the corresponding criteria.

$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
    }

}

Certain lines of code could be combined, but for the sake of understandability I broke them out. You will also want to utilize a try/catch around the actual SOAP call for error handling.

Hopefully this will help shorten someone's learning curve. I know I would have loved to have had this a month ago!!


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" => "[email protected]"
    }
  }
}

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

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>[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>

Tags:

Php

Xml

Api

Soap