I'm trying to query a database from Google AppSheet via cURL. It works 100% in Postman (returns results), but when I copy the code into PHP it returns a NULL set (connects, but doesn't return results).
Postman screenshot w/data returned at bottom: https://imgur.com/9n5UUmB
PHP code as attempted, which returns NULL data...
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.appsheet.com/api/v2/apps/641c9c9f-XXXXXXXXXXXXX/tables/test/Action',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_POSTFIELDS =>'{
"Properties": {
"Locale": "en-US",
"Timezone": "Eastern Standard Time"
}
} ',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'ApplicationAccessKey: V2-XXXXXXXXXXXXX'
),
));
$response = curl_exec($curl);
//echo curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);
echo $response;
echo "Error: ".curl_error($curl)."<br>";
echo "CURLINFO_RESPONSE_CODE: ".curl_getinfo($curl, CURLINFO_RESPONSE_CODE)."<br>";
echo "var_dump: "; echo var_dump($response)."<br>";
echo "var_dump/json_decode: "; echo var_dump(json_decode($response))."<br>";
echo "var_dump/curl: "; echo var_dump($curl)."<br>";
?>
Output of PHP code (from codeblock above): https://imgur.com/2joV4A8
The only thing I changed in the code after using Postman was to add "CURLOPT_SSL_VERIFYPEER = false", as the default value (true) was returning an error when I ran it on the webserver (SSL certificate problem: unable to get local issuer certificate). Using the "CURLOPT_SSL_VERIFYPEER = false" flag returns no error and a status of 200.
As you can see in the Postman screenshot, my test results are clearly visible in the table at the bottom (3 columns: RowNumber, A, B); this is what I'm expecting as an output. In addition, you'll see ("Output" screenshot) I'm not getting any errors, just a NULL return set.
I've tried running this in Postman, which works 100%. I expected this to return data in PHP (V.8.2.6 / IIS 10) however it returns the following (same as screenshot):
CURLINFO_RESPONSE_CODE: 200
var_dump: string(0) ""
var_dump/json_decode: NULL
var_dump/curl: object(CurlHandle)#1 (0) { }
I also tried the following and none of these fixed it:
Set CURLOPT_SSL_VERIFYHOST to 'false'
Added
"User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36", "Accept-Language:en-US,en;q=0.5"
Removed "CURLOPT_ENCODING"
Any help is greatly appreciated. I spent literally the entire day trying to get this to work without luck.
, "Action": "Find"