jquerygoogle-sheetsposthttp-postgoogle-sheets-api

How to append a row to Google Sheets API? It's not working with Jquery: code 403 Unregistered callers


Here's the request URL format I am using currently:

postResURL = https://sheets.googleapis.com/v4/spreadsheets/${SHEET_ID}/values/Reserved!B2:D7:append?valueInputOption=RAW&key=${API_KEY}

Here is my demo code:

const newRow = [[Date.now().toString(), 'xxx@gmail.com', 'some u']];


 $.post({ 
    url: postResURL, contentType: 'application/json', data: JSON.stringify(newRow),
}).done(function(response) {
    if (response.updates) {
    console.log('Row added successfully:', response);
    } else {
    console.error('Error adding row:', response);
    alert('Error adding row.');
}

I kept on getting errors that looks like this:

{
"error": {
"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"
}
}

I checked my google sheet permissions, all the permissions allow for writing.

Interestingly, $.get() works to read values, so I am able to read values from a google sheet, therefore API keys and Client_ID must be correct. However, I don't know why I can't write values to the google sheet, I tried using different combinations of the request URL, I'm not sure if that's the issue or not.


Solution

  • I think Zerosheets would be preferable to you, rather than ironing out all the quirks of Google API.

    Your sheet becomes an URL that you can GET or POST to. From what code you posted there'd be little to no change on how you access the data anyways.