0
votes

I'm trying to use a parameter in a Google web app url to select which tab of a Google Sheet I want to extract data from. The request for data is made via a Chatfuel JSON GET request, which pulls data from the spreadsheet tab and returns it as formatted json code into the chatbot.

When I run the request without passing a parameter and manually enter the sheet tab name into the doGet function of the Google Sheet script as below it works fine.

URL - https://script.google.com/macros/s/xxx-xxx-xxx/exec

function doGet() {
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Retail");
  var data = sheet.getDataRange().getValues();
  elements = create_elements(data)
  if (elements.length != 0) {
     return buildImageGallery(elements);
  } else {
    return notFound()  
  }
}

I just can't quite figure out how to take a parameter from a url (e.g "type"), and then use that as part of the doGet function - this is what I'm roughly trying to do...

URL - https://script.google.com/macros/s/xxx-xxx-xxx/exec?type=Retail

function doGet() {
  var type = e.parameter.type;
  var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(type);
  var data = sheet.getDataRange().getValues();
  elements = create_elements(data)
  if (elements.length != 0) {
     return buildImageGallery(elements);
  } else {
    return notFound()  
  }
}

I'm sure it's soemthing simple, but I'm just getting started with this coding stuff so I'm not sure what I need to change. Thanks in advance for your help.

1

1 Answers

3
votes

Does function doGet(e) work?

Is it a typo or you missed it? The e parameter inside the function.