I am trying to create a blank Google Sheets document in Google Drive from a browser based app. I am able to create a blank file with an unknown file type, but have not been able to create a Google Sheets document.
My code is as follows:
function createfile() {
var config = {
'client_id': '<putyourclient_idhere>',
'scope': 'https://www.googleapis.com/auth/drive'
};
gapi.auth.authorize(config, function() {
var request = gapi.client.request({
'path': '/upload/drive/v2/files',
'method': 'POST'
});
var callback = function(file) {
console.log(file)
};
request.execute(callback);
});
}
I have reviewed the documentation here: https://developers.google.com/drive/v2/reference/files/insert
And the following StackOverflow posts: Creating empty spreadsheets in Google Drive using Drive API (in Python) How to create an empty Google doc / Spreadsheet
I realise that I need to use a mimeType of 'application/vnd.google-apps.spreadsheet'.
I have also been able to successfully create a blank Google Sheets document using the APIs Explorer, but have been unable to determine how this is working. It is doing a post request to:
With a request payload of:
{ "title": "This is a test", "mimeType": "application/vnd.google-apps.spreadsheet" }
But note that the URL is slightly different.