Trying to append a row to a Google Spreadsheet in PHP

There is a new append method: (I am using a service account.)

$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setSubject($delegated_user);
$client->addScope(Google_Service_Sheets::SPREADSHEETS);
$service = new Google_Service_Sheets($client);
$range = 'Sheet1!A:E';
$values = [
    ["a", "b", "C", "D", "E"]
];
$body = new Google_Service_Sheets_ValueRange([
    'values' => $values
]);
$params = [
    'valueInputOption' => "RAW"
];
$result = $service->spreadsheets_values->append($spreadsheet_id, $range, $body, $params);

I had the same problem, there is a lack of documentation about this. But I found a solution. Here is a working example:

// ...

// Create the value range Object
$valueRange= new Google_Service_Sheets_ValueRange();

// You need to specify the values you insert
$valueRange->setValues(["values" => ["a", "b"]]); // Add two values

// Then you need to add some configuration
$conf = ["valueInputOption" => "RAW"];

// Update the spreadsheet
$service->spreadsheets_values->update($spreadsheetId, $range, $valueRange, $conf);

I think it's weird syntax, and I did not found clear documentation about it, I just tried some combination and now it works! Not sure it's the right way, hope it could help.