I have reviewed dozens of StackOverflow posts and tried every suggestion I could find without success. This "string" version works perfectly so I know my Curl is set correctly:
CURLOPT_POSTFIELDS => '{ "select_query":"select Start_DateTime, Event_Duration from Events where Start_DateTime between \'2022-07-25T00:00:00-07:00\' and \'2022-07-31T23:59:59-07:00\'" }',
But when the same string is placed in a variable it fails.
$dateRange_start = '2022-07-25T00:00:00-07:00';
$dateRange_end = '2022-07-31T23:59:59-07:00';
The error I receive is:
Error: {"code":"INVALID_QUERY","details":{"cv_criteria":false,"value":[],"operator":"between"},"message":"value given seems to be invalid for the comparator","status":"error"}
This is the select statement and some of (the dozens of) iterations I've tried. What am I missing here?
CURLOPT_POSTFIELDS => '{ "select_query":"select Start_DateTime, Event_Duration from Events where Start_DateTime between \'$dateRange_start\' and \'$dateRange_end\'" }',
Iterations (mostly from SO suggestions):
\'"$dateRange_start"\'
\'" . $dateRange_start . "\'
${$dateRange_start}
{$dateRange_start}
\'" $dateRange_start "\'
CodePudding user response:
I wasn't able to get any 'takers' on my question but - in case someone else runs into this issue - I finally (after many iterations) discovered the solution. In essence, I needed to add 'dot'concatenation within my escape sequence and ALSO escape the select query itself. The working string is below:
CURLOPT_POSTFIELDS => "{ \"select_query\":\"select Start_DateTime, Event_Duration from Events where Start_DateTime between \'".$dateRange_start."\' and \'".$dateRange_end."\'\"}",
I hope this helps someone.