1
votes

I can't seem to import rows into Google Fusion correctly. I always get a 503 Backend error. My Google Apps Script code is below.

var getDataURL = 'https://www.googleapis.com/fusiontables/v1/tables/{tableID}/import?key='+{apiKey};

var ssDown = SpreadsheetApp.openById({Spreadsheet ID}).getDataRange().getValues();

var options = { "method" : "post", "contentType" : "application/json", "headers" : { "Authorization" : "Bearer " + {token}, "Accept" : "application/json", }, 'encoding' = 'auto-detect', 'payload' = ssDown.toString(); } };

var output = UrlFetchApp.fetch(getDataURL,options).getContentText();

1
I've been seeing this backend error but on scripts nothing to do with Fusion tables. Take a look at issue 2759 ( code.google.com/p/google-apps-script-issues/issues/… )Srik
The response is coming from Fusion Tables, not GAS. I have copied the error below. [13-05-19 11:18:20:362 BST] { "error": { "errors": [ { "domain": "global", "reason": "backendError", "message": "Backend Error" } ], "code": 503, "message": "Backend Error" } }ajb1970

1 Answers

1
votes

The issue was caused by careless coding on my part. The correct code is:

var getDataURL = 'https://www.googleapis.com/upload/fusiontables/v1/tables/{tableID}/import';
var options = { "method" : "post",
              "contentType" : "application/octet-stream",
              "headers" : {
                "Authorization" : "Bearer " + {token},
                "Accept" : "application/json",
              },
            }
var ssDown = SpreadsheetApp.openById({sheetID}).getDataRange().getValues().toString();
options.payload = ssDown;
var output = UrlFetchApp.fetch(getDataURL,options).getContentText();