I'm trying to make an API call (List>Leads), which aside from this current issue was working fine (well, sort of) when my where clause was ["type" => "currentMonth"], but now I'm attempting to use ["type" => "between" , "values" => from, to ], but I have zero idea what format is expected of me? I just assumed YYYY-MM-DD. It's not failing, or throwing an error, it's just giving me everything. It also happens to be returning leads that don't even have anything in the createdAt field (failed import), and it appears to be letting deleted leads in in spite of the "isFalse","deleted".
Can somebody give me a bit of guidance here? The API is working, it's just not doing what I expect it to. I feel like my where clauses are more of a suggestion than a rule. Actually, they're just being ignored entirely.
I'm wondering if I should just add hard-coded day, month, and year fields to the Lead entity and sidestep the date format issue entirely, but that doesn't help me anyway because it's giving me deleted leads too. I'm going to try a simpler query that it could not possibly get wrong (assuming it even tries).
Can somebody give me a bit of guidance here? The API is working, it's just not doing what I expect it to. I feel like my where clauses are more of a suggestion than a rule. Actually, they're just being ignored entirely.
I'm wondering if I should just add hard-coded day, month, and year fields to the Lead entity and sidestep the date format issue entirely, but that doesn't help me anyway because it's giving me deleted leads too. I'm going to try a simpler query that it could not possibly get wrong (assuming it even tries).
Code:
require_once('vendor/autoload.php'); use Espo\ApiClient\Client; $url = REDACTED; $headers = [ "Content-Type:application/json", "Accept:application/json", "X-Api-Key:REDACTED" ]; $month = $_GET['month']; if(isset($_GET['year'])){ $year = $_GET['year']; // format incoming year/month into YYYY-MM-01, then subtract a day $fromDate = date_format( date_sub( date_create( $year."-".str_pad($month, 2, '0', STR_PAD_LEFT)."-01" ), date_interval_create_from_date_string("1 day") ), "Y-m-d" ); // format incoming year/month into YYYY-(MM+1)-01 $month = $month + 1; $toDate = date_format( date_create( $year."-".str_pad($month,2,'0', STR_PAD_LEFT)."-01" ), "Y-m-d" ); } if($month == "currentMonth"){ $data = [ "select" => [ "createdAt", "howDidTheyHearAboutUs", "showedUpForCall", "showedUp4Assessment", ], "where" => [ [ "type" => "and", "value" => [ [ "type" => $month, "attribute" => "createdAt", ], [ "type" => "isFalse", "attribute" => "deleted", ], ], ], ], ]; }else if(isset($month)&&isset($year){ $data = [ "select" => [ "createdAt", "howDidTheyHearAboutUs", "showedUpForCall", "showedUp4Assessment", ], "where" => [ [ "type" => "and", "value" => [ [ "type" => "between", "attribute" => "createdAt", "value" => [ $fromDate, $toDate ] ], [ "type" => "isFalse", "attribute" => "deleted", ], ], ], ], ]; } $payload = json_encode($data); $ch = curl_init( $url ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_Setopt( $ch, CURLOPT_CUSTOMREQUEST, "GET"); $response = curl_exec($ch); curl_close($ch); echo json_encode($response); ?>
Comment