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

前端 未结 3 1991
旧巷少年郎
旧巷少年郎 2021-02-04 17:33

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 Au

3条回答
  •  执念已碎
    2021-02-04 18:27

    @JesseQ great example! Helped me a ton. Here's how I set it up to run any Five9 report in their arsenal including ones you create yourself. For custom reports, you'll need to create a new folder/report and place it in the "Custom Reports" section on the Five9 web portal. Hope this helps.

    MySQL Database Connection (dbConnect.php)

    connect_error) {
            die('Connect Error: (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);
        }
    ?>
    

    Five9/MySQL Database Import

    setDate(2015, 07, 22);
        $endDate->setDate(2015, 07, 22);
        $five9 = "https://api.five9.com/wsadmin/v2/AdminWebService?wsdl";
        $five9Credentials = array("login" => "your Five9 username", "password" => "your Five9 password");
        $soap = new SoapClient($five9, $five9Credentials);
        $runReportParam["criteria"]["time"] = array("start" => $startDate->format("Y-m-d\T00:00:00"), "end" => $endDate->format("Y-m-d\T23:59:59"));
        $runReportParam["folderName"] = "My Custom Reports";
        $runReportParam["reportName"] = "My First Report";
        $runReportResult = $soap->runReport($runReportParam);
        if(isset($runReportResult->return)){
            $runReportData = $runReportResult->return;
            $isReportRunningParam["identifier"] = $runReportData;
            $isReportRunningParam["timeout"] = 10;
            $isReportRunningResult = $soap->isReportRunning($isReportRunningParam);
            if(empty($isReportRunningResult->return)){
                $getReportResultParam["identifier"] = $runReportData;
                $getReportResult = $soap->getReportResult($getReportResultParam);
                if(isset($getReportResult->return->records)){                
                    $getReportResultData = $getReportResult->return->records;
                    echo "[" . date("Y-m-d h:i:s") . "] " . $runReportData . "\n";
                    for($x = 0; $x < $xx = count($getReportResultData); $x++){
                        $query = "REPLACE INTO MyTable(
                            CallDate, CallTime, DNIS, Disposition, Zip, AreaCode, ANI)
                            VALUES (?,?,?,?,?,?,?)";
                        $result = $mysqli->prepare($query);
                        $result->bind_param("sssssss", 
                            $getReportResultData[$x]->values->data[0],
                            $getReportResultData[$x]->values->data[1],
                            $getReportResultData[$x]->values->data[2],
                            $getReportResultData[$x]->values->data[3],
                            $getReportResultData[$x]->values->data[4],
                            $getReportResultData[$x]->values->data[5],
                            $getReportResultData[$x]->values->data[6]
                        );
                        $result->execute();
                        $result->store_result();
                        if ($result->error){
                            die('Connect Error: (' . $result->errno . ') ' . $result->error);
                        }
                        echo "[" . date("Y-m-d h:i:s") . "] " . $x . "\n";
                    }
                } else {
                    echo "Error: " . $runReportData . " returned no data";
                }
            } else {
                echo "Error: " . $runReportData . " exceeded the report runtime limit";
            }
        } else {
            echo "Error: " . $runReportParam["reportName"] . " wasn't found";
        }
        $mysqli->close();
    ?>
    

提交回复
热议问题