整合批次資料 API 並在僅顯示已過濾項目之一時出現問題。 api範例是:https://developer.batchdata.com/docs/batchdata/batchdata-v1/operations/create-a-property-skip-trace
在此範例中,我嘗試僅顯示電話號碼或電子郵件欄位。顯示完整的結果,所以我知道 api 正在工作...但是,我無法顯示過濾後的項目,如下所示:
<?php $email; ?> <?php echo $response->response->results->result[0]->results->persons->email;?> <?php echo $response->options->customProjection[0]->results->persons->phoneNumbers->number;?>
這是我現在擁有的完整程式碼:
<?php $location = $entity->getSingleFieldValue('field_site_address'); $street = $location['street']; $city = $location['city']; $state = $location['province']; $email = $response->response->results->result[0]->results->persons->email; $curl = curl_init(); curl_setopt_array($curl, [ CURLOPT_URL => "https://api.batchdata.com/api/v1/property/skip-trace", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 30, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => "{\n \"requests\": [\n {\n \"propertyAddress\": { \"street\": \"$street\", \"city\": \"$city\", \"state\": \"$state\" } }\n ]\n}", CURLOPT_HTTPHEADER => [ "Authorization: Bearer xxxxxx", "Content-Type: application/json" ], ]); $data = simplexml_load_string($result); $response = curl_exec($curl); $err = curl_error($curl); curl_close($curl); ?> <?php if ($err) { echo "cURL Error #:" . $err; } else { echo $response; }?> <?php $email; ?> <?php echo $response->response->results->result[0]->results->persons->email;?> <?php echo $response->options->customProjection[0]->results->persons->phoneNumbers->number;?>
在嘗試存取欄位之前,您需要先解碼 JSON
在您的 else 語句中加入此內容
我不確定您返回的確切JSON 回應是什麼,但請查看示例,您可能需要使用它來獲取電子郵件和電話號碼,但如果沒有實際回應,我無法確認這一點(如果包含電子郵件和電話號碼,請勿發佈您的實際回覆)