Hi, How am I able to POST this value to my API?{ "values":[ [ "11:00 AM", "Name Last", "Globe", "Company", "No Reason", "2000", "c:/" ] ]}I recieve 400 error everytime
Marco Arede wrote:
Hi Reyco Seguma,
Good to know it's solved.
Can you tell us more details on how you solved? What's the difference between what you had before and the Javascript you have now?
Cheers!
I have no problem on getting data from Google API.But I am having a problem on POST request.I tried everything to use the OS Rest API to consume an API from Google.with Oauth2 and spreadsheet scope. But, I am having problem with the JSON structuregiven by the Google API.{ "values":[ [ "11:00 AM", "Name Last", "Mark", "Company", "No Reason", "2000", "c:/" ] ]}I tried to use text/plain for the POST body but still it doesn't work.So I decided to use Javascript request instead to trigger the post request.It successfully posted the value.Here is my solution:
SyntaxEditor Code Snippet
var xhr = new XMLHttpRequest(); var url = 'https://sheets.googleapis.com/v4/spreadsheets/" + SpreadsheetId + "/values/Sheet1:append?valueInputOption=USER_ENTERED&key=" + APIKey + "'; xhr.open('POST', url, true); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.setRequestHeader('Authorization', 'Bearer xxxxxxxx'); xhr.onreadystatechange = function () { if (xhr.readyState === 4 && xhr.status === 200) { var json = JSON.parse(xhr.responseText); } }; var data = JSON.stringify({ "values":[ [ "11:00 AM", "Name Last", "Mark", "Company", "No Reason", "2000", "c:/" ] ] }); xhr.send(data);
If you have a better solution. I will take a look at it.thanks.
Did you checked how and why the API is providing you a bad Request (might be their format)?
Hi.Google Spreadsheet API is using this JSON format to send POST request.I tried using text/plain but still it doesn't work.It just returns 400.I already check the JSON format on JSON formatter it was correct.
Reyco Seguma wrote:
I enable the Spreadsheet Library on the Google API console.So that i'll be able to access the Google Spreadsheet API by adding the "scope"for the spreadsheet.By adding the scope of the spreadsheet during the login, it returns a token withpermission Spreadsheet API.
I manage to make it work..but I used Javascript as a requestor.
Please let us understand more about the context of your problem.
Thanks for sharing that. I think you can mark this post as solved.
Good luck with the app!