1

I am trying to convert Google Sheet to XLSX and download it via HTTP (all done by script, exported again on every request).

First, I tried the code solution provided here and it did indeed work and sent the file by email.

Then, I tried to do the request and download the file on my own via code/curl. As I know URL and Authorization Bearer token it should have been easy.

var url = "https://docs.google.com/spreadsheets/d/" + file.getId() + "/export?format=xlsx"; 
var token = ScriptApp.getOAuthToken();

The cUrl example for this looked like this:

curl --location --request GET 'https://docs.google.com/spreadsheets/d/SPREADSHEET_ID/export?format=xlsx' --header 'Authorization: Bearer TOKEN_ID'

It did work properly for some time but recently it stopped working, even though it does work within Google Script returning proper response code (200) and the result. Currently it returns Error code 400: Bad Request instead if done from curl/external code.

Did I miss some update from Google that made such requests not possible from outside of Google Script itself?

1 Answers1

0

It looks like it was a bug that Google has finally fixed! Now it does work properly.

For those who want to get the URL in another way, here's alternative approach (but a bit slower). It saves the file to Google Drive and creates accessible public link to it. Please note that it will create a new file in directory on each request, so you might want to delete them by code first.

var dir = DriveApp.getFolderById("drive_folder_id");
var file = dir.createFile(blob).setName('file.xlsx'); 
file.setSharing(DriveApp.Access.ANYONE_WITH_LINK,DriveApp.Permission.VIEW); 
var url = file.getDownloadUrl();