0

I need to POST or PUT data into a google sheets sheet using the requests package though I do not know how to do this.

I know how to GET data:

const request = require('request');
const sheetget = 'https://sheets.googleapis.com/v4/spreadsheets/SHEET_ID/values/RANGE?key=API KEY';
request.get(sheetget, (error, response, body) => {
let json = JSON.parse(body);
let values = json['values']
}

[the sheet is public (with a link) so that the API key works and I don't need to use an Oauth2 thingy]

I tried using this: https://developers.google.com/apis-explorer/#p/sheets/v4/sheets.spreadsheets.values.update to try to get the HTTP request but I don't know what to do with the request body.. Do I put it in the url or what..

Also, I'm new to javascript and all of this stuff so please keep your answers newb-friendly. Thanks!

EDIT:

I don't know how to use PUT to update data on the sheet.

W0LFB0MB
  • 55
  • 10
  • 1
    [The method of spreadsheets.values.update](https://developers.google.com/sheets/api/reference/rest/v4/spreadsheets.values/update) is requested using PUT method. API key cannot be used to PUT and POST methods. And also when you use GET method using API key, the Spreadsheet is required to be shared. In your case, please use OAuth2 as the error message says, or use Service account. – Tanaike Feb 18 '19 at 22:18
  • @Tanaike I've not yet figured out how to use PUT or anything to update the existing values on the spreadsheet – W0LFB0MB Feb 18 '19 at 22:37
  • Thank you for replying. In order to correctly understand about your current issue, can you update your question? By this, I think that it will help users think of about your issue. – Tanaike Feb 18 '19 at 22:38
  • Easiest way is to use the client library: https://www.npmjs.com/package/googleapis and the associated tutorial code is found in the Sheets API documentation, linked by Tanaike. As mentioned, you **MUST** authorize with OAuth2 in order to write data -- even to a public, anonymously editable resource. – tehhowch Feb 19 '19 at 00:55
  • If you can, please provide a public spreadsheet and API key for us to try on... – cbdeveloper Feb 21 '19 at 12:54

0 Answers0