0

I had a syntax error with a simple code line of google sheet app scripts, I am not experienced in app scripts but this is pretty straight forward syntax from any programming language. Kindly show me if I'm missing something?

I tried changing header into 'header' or "header" but syntax error was on it not recognizing the format

function loadInformation(){

  //Set up service and check access
  var firebaseService = getFirebaseService();
  if (firebaseService.hasAccess()) {   
    //Set up google sheet and header row
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var Sheet = ss.getSheetByName("<YOUR SHEETNAME>");
    Sheet.clearContents();
    Sheet.appendRow([<YOUR SHEET HEADERS>]); 

    //Set up reference
    var databaseURL = "https://xxxxxx.firebaseio.com/";
    var ref = "xxxxxx";
    var requestURL = databaseURL+ref+".json";

    //API Call
    var response = UrlFetchApp.fetch(requestURL, {
     headers: {
       Authorization: 'Bearer ' + firebaseService.getAccessToken()
     },
      method: 'get'
    });

    //Parse JSON
    var data = JSON.parse(response.getContentText());

    //Loop through JSON and append row
    for (item in data){   
      var newRow = [item,];
      Sheet.appendRow(newRow);
    } 
   }  
  } else {

    //Show authorization URL to user
    var authorizationUrl = firebaseService.getAuthorizationUrl();
     showDialog(authorizationUrl);
  }
}

Error Result :

Syntax error. (line 20, file "loadInformation") Dismiss

0

2 Answers 2

1

Your "else" is outside the function. Delete the " } " before the "else".

Also, if this line is left like this it will throw another error. Be sure to have the headers actually there:

    Sheet.appendRow([<YOUR SHEET HEADERS>]); 

like this:

    Sheet.appendRow(["a", "b", "c"]); 
Sign up to request clarification or add additional context in comments.

Comments

1

Like Mark said, your 'else' is outside the function.

And if you change this

Sheet.appendRow([<YOUR SHEET HEADERS>]);

to

Sheet.appendRow(["<YOUR SHEET HEADERS>"]); 

the syntax error should go away.

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.