0
votes

I'm working on an app that adds entries to a google sheet. Authorization is already working and I can create a sheet, but don't know how to set title due to difficult/lacking REST API documentation, only library code is shown.

I'm using: PHP7, cURL and the direct REST API endpoints, not the library.

To create a new spreadsheet, I call: https://sheets.googleapis.com/v4/spreadsheets with the access_token (bearer)

That works, but I would like to set the title in that same request or in the next request.

I tried: https://sheets.googleapis.com/v4/spreadsheets/SPREADSHEETID:batchUpdate

$post_date = [
                'requests' => [
                'title' => 'Test '.$params['id'].' '.date('Y-m-d H:i:s').''
                ]
            ];

But it says invalid json payload. Also, I think it would be more efficient if I could set the title in the first request.

1

1 Answers

0
votes

I found the answer, it was:

$post_data = [
      "properties" => [
        "title" => "Test ".$params['id']." ".date('Y-m-d H:i:s').""
      ]
    ];

And then I had to JSON encode it in cURL instead of regular array.