Reputation: 11
My first post, related to the following post How do I set a basic filter in php using google sheets api?
I have implemented code below but get this message and I'm not sure what's the cause:
Invalid JSON payload received. Unknown name "requests" at 'requests[0]': Cannot find field.
$criteria = new \stdClass();
$criteria->{'2'} = array(
'condition' => array(
'type' => 'NUMBER_EQ',
'values' => array(
'userEnteredValue' => '5'
)
)
);
$requests = [
new Google_Service_Sheets_Request( array(
'requests' => array(
'setBasicFilter' => array(
'filter' => array(
'range' => [
'sheetId' => 0,
'startRowIndex' => 4,
'endRowIndex' => 20,
'startColumnIndex' => 0,
'endColumnIndex' => 11
],
'criteria' => $criteria
),
),
'includeSpreadsheetInResponse' => true,
'responseIncludeGridData' => true
)
)
)
];
$requestBody = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array('requests' => $requests));
$response = $sheets->spreadsheets->batchUpdate($spreadsheetId, $requestBody);
Upvotes: 1
Views: 1590
Reputation: 201428
'userEnteredValue' => '5'
to an array.'requests' => array(,,,)
is not required in new Google_Service_Sheets_Request()
. Because array('requests' => $requests)
is used.'includeSpreadsheetInResponse' => true,
and 'responseIncludeGridData' => true
outside of $requests
.When above points are reflected to your script, it becomes as follows.
$criteria = new \stdClass();
$criteria->{'2'} = array(
'condition' => array(
'type' => 'NUMBER_EQ',
'values' => [array('userEnteredValue' => '5')]
)
);
$requests = [
new Google_Service_Sheets_Request( array(
'setBasicFilter' => array(
'filter' => array(
'range' => [
'sheetId' => 0,
'startRowIndex' => 4,
'endRowIndex' => 20,
'startColumnIndex' => 0,
'endColumnIndex' => 11
],
'criteria' => $criteria
)
)
)
)
];
$requestBody = new Google_Service_Sheets_BatchUpdateSpreadsheetRequest(array(
'requests' => $requests,
'includeSpreadsheetInResponse' => true,
'responseIncludeGridData' => true
));
$response = $sheets->spreadsheets->batchUpdate($spreadsheetId, $requestBody);
$criteria->{'2'}
can be used, and also, $criteria->{'1'}
instead of $criteria->{'2'}
can be used.Upvotes: 1