我正在使用PHP从众人瞩目的CRM中提取数据。我正在点击prospect_find API调用,它允许我返回一个潜在客户ID列表以及每个潜在客户的JSON编码的prospect_view对象。我可以分离潜在客户ID,但我无法进入下一级别的日期以提取我需要的实际潜在客户数据
这是我调用API的代码
$find_prospects = array(
'username' => $LLAPI_USER,
'password' => $LLAPI_PASS,
'method' => 'prospect_find',
'campaign_id' => '272',
'start_date' => $startDate,
'start_time' => '00:00:00',
'end_date' => $endDate,
'end_time' => '23:59:59',
'return_type' => 'prospect_view'
);
$ch = curl_init($limelight_crm_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($find_prospects));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$retOrder = curl_exec($ch);
curl_close($ch);
parse_str($retOrder);
echo $retOrder;
if ($retOrder === false) {
echo "No prospects to extract";
} else {
//var_dump ($data);
$prospectData = json_decode($data[0]);
echo $prospectData;
$counter = 0;
$all_prospect_counter = 0;
$prospectids = Array();
$total_prospect = count(explode(',', $prospect_ids));
foreach (explode(',', $prospect_ids) AS $prospectid) {
$prospectData = json_decode($data);
// print_r ($prospectData);
echo $prospectData[$prospectid]->$response_code;
// $arr = explode(',', $prospect_ids);
// print($arr[$counter]->{"response_code"});
$counter++;
}
截断的响应在这里:
response_code=100&total_prospects=1182&prospect_ids=3658707,&data=
{"3658707":
{"response_code":"100",
"campaign_id":"272",
"first_name":"XXXX",
"last_name":"XXXX",
"address":"XX",
"address2":"",
"city":"XXXX",
state":"XX",
"state_id":"XX",
"zip":"XXXXX",
"country":"XX",
"phone":"XXXX",
"email":"XXXXXX",
"ip_address":"XXXXXX",
"date_created":"2017-02-12+00%3A04%3A07",
"affiliate":"XX",
"sub_affiliate":"XXXX"
}
如果有人可以帮我指出正确的方向,我会很感激。谢谢
答案 0 :(得分:0)
$prospectData = json_decode($data, true);
$counter = 0;
$all_prospect_counter = 0;
$prospectids = Array();
$total_prospect = count(explode(',', $prospect_ids));
$arr = explode(',', $prospect_ids);
foreach($prospectData as $prospect){
$first_name = $prospect['first_name'];
$last_name = $prospect['last_name'];
$address = $prospect['address'];
$city = $prospect['city'];
$state = $prospect['state'];
$zip = $prospect['zip'];
$email = $prospect['email'];
$date_created = $prospect['date_created'];
$campaign_id = $prospect['campaign_id'];
$query_pop_temp = "INSERT INTO `hydra`.`Prospects` (`ProspectID`,`FirstName`,`LastName`,`StreetAddress`, `City`,`State`, `zip`,`Emailaddress`,`Created`,`Campaign`, `ListID`)
VALUES ($arr[$counter], '$first_name', '$last_name', '$address', '$city', '$state', '$zip', '$email', '$date_created', $campaign_id, 'CxBkt4')";
$result_pop_temp = $mysqli->query($query_pop_temp);
$counter++;
}