1

I am trying to append some data to a Google Sheets spreadsheet using a HTML POST Request. I am having some difficulty in solving the 404 error I get when sending the request. My request code is shown below:

var httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = function() {
  if (httpRequest.readyState == XMLHttpRequest.DONE) {
    alert(httpRequest.status);
  }
}

var params = {
  "values": [
     [
       "value1",
       "value2"
     ]
  ]
}

httpRequest.open('POST', 'https://sheets.googleapis.com/v4/spreadsheets/' + spreadsheetID + 'values/Sheet1!B2:L2:append', true)
httpRequest.setRequestHeader('Authorization', 'Bearer ' + accessToken);
httpRequest.setRequestHeader('Content-Type', 'application/json');
httpRequest.send(JSON.stringify(params));

I have gained the necessary permissions in the access token, since I am able to create sheets, but I think there might be an issue with my url. Thanks in advance!

1 Answer 1

1

From the documentation sheets.append

https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/{range}:append

I think you are missing a / before values

'https://sheets.googleapis.com/v4/spreadsheets/' + spreadsheetID + '/values/Sheet1!B2:L2:append', true)

Try testing it using the Try this api on the documentation page here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.