6

This is extremely similar to another question answered here about how to GET spreadsheet data, but I'm trying to append data to a spreadsheet. Here's my sample curl request:

curl -H "Content-Type: application/json" -X POST -d '{"range":"A1","majorDimension":"ROWS","values":["Frank2"]}' https://sheets.googleapis.com/v4/spreadsheets/{SPREADSHEET_ID}/values/A1:append?valueInputOption=RAW&key={API-KEY}

Here's the response:

{
  "error": {
    "code": 401,
    "message": "The request does not have valid authentication credentials.",
    "status": "UNAUTHENTICATED"
  }
}

Can this be done only using an API Key or am I doing something wrong? The documentation suggests it is possible if the spreadsheet is shared publicly.

Community
  • 1
  • 1
blinkmacalahan
  • 499
  • 5
  • 18

3 Answers3

7

Requests that write to the spreadsheet require authentication credentials. Even if the spreadsheet is shared publicly, when writing through the API the write must be attributed to a user.

Sam Berlin
  • 3,603
  • 12
  • 23
1

This is currently broken. You can not edit the document (even if public) with only an APIKey.

https://issuetracker.google.com/issues/73974970

sww314
  • 1,252
  • 13
  • 17
  • FWIW, per the above answer, write requests intentionally requires user authorization and does not work with only an apikey. If the documentation states otherwise, can you please point me to those docs? – Sam Berlin Feb 28 '18 at 15:34
0

https://developers.google.com/sheets/api/guides/authorizing#APIKey

The page above states the following:

Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported. If your application uses Google Sign-In, some aspects of authorization are handled for you.