I am trying to connect my Google Sheet to a PHP script using a Google Apps Script. This requires sending payload with the UrlFetchApp
function. And, this is where the connection betweenn Script and PHP goes wrong.
The connection works, when I replace the echo
value in the PHP script to a non variable, there is a response. Also, my response code is 200
.
But, sending or reading my payload is the problem.
Google Apps Script:
var payload = {"A": "12345"};
var url = 'myurl/stats.php'
var response = UrlFetchApp.fetch(
url,
{
"method": "GET",
"contentType": "application/json",
"payload": JSON.stringify(payload),
}
);
var responseCode = response.getResponseCode();
var responseBody = response.getContentText();
Logger.log(responseCode);
Logger.log(responseBody);
PHP:
<?php
$A = $_GET["A"];
echo json_encode("Hello: ".$A);
?>
Note: Using a browser, this PHP script is working.
I expect responseBody
to be "Hello: 12345"
but the actual output is "Hello: "