Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sheets API v4 append request receives HTTP 401 response for public feeds using API Key

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.

like image 913
blinkmacalahan Avatar asked Dec 02 '16 00:12

blinkmacalahan


People also ask

How do I use a Google spreadsheet API key?

The key identifies your project and provides API access, quota, and reports. The API supports several types of restrictions on API keys. If the API key that you need doesn't already exist, then create an API key in the Console by clicking Create credentials > API key.

Can Google Sheets pull data from an API?

We can connect a Google Sheet to an API and bring data back from that API (e.g. iTunes) into our Google Sheet using Google Apps Script.

Can Google Sheets make API calls?

Calling a REST API in Google Sheets is as easy as installing the Apipheny app, then opening the app in your Google Sheet, entering your API request, and clicking “Run”. Keep reading for instructions on how to import REST API data into Google Sheets.


2 Answers

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.

like image 198
Sam Berlin Avatar answered Oct 17 '22 22:10

Sam Berlin


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

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

like image 26
sww314 Avatar answered Oct 17 '22 20:10

sww314