Php CLIO返回按显示编号显示的事件编号

Php CLIO返回按显示编号显示的事件编号,php,clio-api,Php,Clio Api,克里奥似乎没有办法,只能在这里问。 我来了 我有显示号码,我想查询问题ID。 这似乎是不可能的,除非我在循环抛出结果时执行x-bulk查询 有没有人可以用一个简单的查询来实现这一点 以下是我到目前为止对PHP的了解 function matter_one ( $token,$refresh_toke ) { $header = 'Authorization: bearer '.$token."\r\n"; //echo $header."\r\n"; $offset =

克里奥似乎没有办法,只能在这里问。 我来了

我有显示号码,我想查询问题ID。 这似乎是不可能的,除非我在循环抛出结果时执行x-bulk查询

有没有人可以用一个简单的查询来实现这一点

以下是我到目前为止对PHP的了解

function matter_one ( $token,$refresh_toke ) {
    $header = 'Authorization: bearer '.$token."\r\n";
    //echo $header."\r\n";
    $offset = 0;
    $url = 'https://app.clio.com/api/v4/matters.json?&fields=id,description,display_number';
    //echo $url."\r\n";
    $ch = curl_init();
    //curl_setopt($ch, CURLOPT_VERBOSE, true); //used for trouble shooting.
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_HEADER, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $resp = curl_exec($ch);
    print "curl response is:" . $resp;
    die();

如果问题是您不想执行x-bulk,那么这里的代码将提取所有信息,您可以修改代码以在每个页面返回的数据中查找项目,也可以在最终数组中查找

    function performListRequestAllMatters()
{
    $header = 'Authorization: bearer ' . $this->token;
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $this->base . $this->API_version . 'matters' . '?fields=id,display_number');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

    $response = curl_exec($ch);

    if (!$response) {
        die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
    } elseif (200 != curl_getinfo($ch, CURLINFO_HTTP_CODE)) {
        echo "Bad Response Code!";
        echo "\n";
        echo "Response HTTP Status Code : " . curl_getinfo($ch, CURLINFO_HTTP_CODE);
        echo "\n";
        echo "Response HTTP Body : " . $response;
    } else {

        $json = json_decode($response, true);
        $list = $json['data'];

        while (isset($json['meta']['paging']['next'])) {
            // process a new request until all pages have been retrieved
            curl_setopt($ch, CURLOPT_URL, $json['meta']['paging']['next']);

            $response = curl_exec($ch);
            $json = json_decode($response, true);
            $newList = $json['data'];

            $list = array_merge($list, $newList);
        }

    }
    curl_close($ch);

    return $list;
}

如果您有10000多条记录,则必须使用批量。 此函数在获取所有记录时非常有效。 然后你可以找到你需要的号码

function matter_ID_display ( $token,$refresh_toke ) {
            // this returns all the matter ID and display name

            //adding X-BULK
            $header = 'Authorization: bearer '.$token."\r\n"."X-BULK: true";
            //echo $header."\r\n";
            $offset = 0;
            $url = 'https://app.clio.com/api/v4/matters.json?offset='.$offset.'&fields=id,display_number';
            $cookie_jar = 'C:\Sites\Project for simmons and flecter\PHP\tmp\cookies.txt';
            $cookie_jar2 = 'C:\Sites\Project for simmons and flecter\PHP\tmp\cookies2.txt';
            //echo $url."\r\n";
            $ch = curl_init();
            //curl_setopt($ch, CURLOPT_VERBOSE, true); //used for trouble shooting.
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array($header));
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_HEADER, true);
            curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $resp = curl_exec($ch);
            //print "curl response is:" . $resp;
            if( !$resp ) {
                die('Error: "' . curl_error( $ch ) . '" - Code: ' . curl_errno( $ch ) );
            }

            else if ( 200 != curl_getinfo( $ch, CURLINFO_HTTP_CODE ) ) {
                echo "Expected code 202";
                echo "\n";
                echo "Response HTTP Status Code : " . curl_getinfo( $ch, CURLINFO_HTTP_CODE );
                echo "\n";
                //echo "Response HTTP Body : " . $resp;
            }

            //$resp = json_encode($resp);
            $headers = get_headers_from_curl_response($resp);
            //$headers = json_encode($headers);
            //print_r ($headers);
            $url = $headers["Location"];
            echo "url for getting the bulk data\r\n";
            echo $url."\r\n";
            echo "\n";

            curl_close($ch);
            //sleep for x seconds
            //have to sleep due to processing at clio
                $seconds = 20;
                echo "Sleeping for ".$seconds." seconds\r\n";
                sleep($seconds);
                echo "\n";  
        // seperate curl_
                $curl = curl_init();

                curl_setopt_array($curl, array(
                  CURLOPT_URL => $url,
                  CURLOPT_COOKIEJAR => $cookie_jar2,    
                  CURLOPT_COOKIEFILE=> $cookie_jar2,
                  CURLOPT_CUSTOMREQUEST => "GET",
                  CURLOPT_HTTPHEADER => array("authorization: Bearer ".$token),
                  CURLOPT_SSL_VERIFYPEER => false,     // Disabled SSL Cert checks
                  CURLOPT_AUTOREFERER    => true,     // set referer on redirect
                  CURLOPT_FOLLOWLOCATION => true,     // follow redirects
                  CURLOPT_ENCODING => "",  // handle all encodings
                  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                  CURLOPT_RETURNTRANSFER => true, // return web page
                 ));

                $response = curl_exec($curl);
                $err = curl_error($curl);

                curl_close($curl);
                if ($err) {
                  echo "cURL Error #:" . $err;
                } else {
                      echo 'Curled first time';
                      echo "\n";
                      // have to curl two times one without authorization
                        echo "\n";
                        Echo "cURL repeat";
                        echo "\n";
                        $curl = curl_init();

                            curl_setopt_array($curl, array(
                            CURLOPT_URL => $url,
                            CURLOPT_COOKIEJAR => $cookie_jar2,  
                            CURLOPT_COOKIEFILE=> $cookie_jar2,
                            CURLOPT_CUSTOMREQUEST => "GET",
                            //CURLOPT_HTTPHEADER => array("authorization: Bearer ".$token),
                            CURLOPT_SSL_VERIFYPEER => false,     // Disabled SSL Cert checks
                            CURLOPT_AUTOREFERER    => true,     // set referer on redirect
                            CURLOPT_FOLLOWLOCATION => true,     // follow redirects
                            CURLOPT_ENCODING => "",  // handle all encodings
                            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                            CURLOPT_RETURNTRANSFER => true, // return web page
                            ));

                            $response = curl_exec($curl);
                            $err = curl_error($curl);
                        curl_close($curl);
                        if ($err) {
                            echo "cURL Error #:" . $err;
                        } else 
                            {echo 'Good Reponse from Curl second time';
                            echo "\n";}
                    }

                $response_Decode = json_decode($response);
                //print_r ($response_Decode);

                    // got the data. Now just need to turn to a clean array and save to file.
                    //die('Before Array clean up');

            //clean and make into an array
                $response_Decode=$response_Decode->data;
                $response_Decode=$response_Decode[0];
                //print_r ($response_Decode);
                //die(); //For testing
                $matter_array = array();     
                if(!empty($response_Decode->data) && is_array($response_Decode->data)) {
                    foreach ($response_Decode->data as $info) {
                        $d = array();
                        $d[] = $info->display_number;
                        $d[] = $info->id;
                        $matter_array[] = $d;
                    }
                }

                print_r($matter_array);  //For testing
                die(); //For testing

            //matter_array is a full array of all matter ID and Matter Display numbers  
            return $matter_array; }

有一个更好的方法,使用


您需要循环并检查显示编号是否实际匹配,因为100140和100140B以及10014000也将返回。

我收到一个错误。注意:未定义的索引:第399行C:\Sites\PHP\lib\cliov4.PHP中的数据这是$newList=$json['data'];警告:array_merge():参数#2不是第401行C:\Sites\PHP\lib\cliov4.PHP中的数组,即$list=array_merge($list,$newList);所以我想出来了。你只能做这么多的请求。它用完了,然后就出错了,死了。这就是为什么我必须做大量的工作。clioapi很烂。我应该能够根据显示名称请求一条记录