Using javascript fetch() to retrieve a single value from a Google sheet works perfectly fine for me. However, when attempting to read multiple ranges, I encounter a 403 error.
The following code executes without any issues:
const apiKey = 'insert-your-key';
const spreadsheetId = 'insert-your-sheet-id';
const sheetName = 'Sheet1';
values = values = fetch(`https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values/${sheetName}?key=${apiKey}`)
.then(response => response.json())
.then (data => console.dir (data))
.catch(error => console.error('Encountered an error while reading Google Sheet: ', error));
However, replacing the fetch() method with values.getBatch results in a 403 error being displayed in the browser's Inspect panel:
values = fetch(`https://sheets.googleapis.com/v4/spreadsheets/${spreadsheetId}/values:batchGet?ranges=Sheet1!A1:A2&ranges=subtitle!B1:B2?key=${apiKey}`)
The specific error message reads as follows:
code: 403
message: "Method doesn't allow unregistered callers (callers without established identity). Please use API Key or other form of API consumer identity to call this API."
status: "PERMISSION_DENIED"
You can find more information about values:getBatch in the documentation available at https://developers.google.com/sheets/api/samples/reading