title: Accessing headers of a google spreadsheet using HTTP GET and Google App Script
body: <p>I'm trying to return the header row of a Google spreadsheet using doGet() in a Google App Script that's running as a WebApp. I'm using a HTML form to send the GET request to the WebApp and it's all working except I don't know how to return the headers to my javascript. I'll post my code:</p>
  
  <pre><code>HTML:
          &lt;form id="getForm" method="get" action="My URL for WebApp"&gt;
          &lt;label for="sheetGetID"&gt;SheetID&lt;/label&gt;
          &lt;input type="text" name="sheetGetID" id="sheetGetID" value=""&gt;
          &lt;button class="ui-btn" onclick='submitGET()'&gt;Submit&lt;/button&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>function submitGET() {
    var headers = $("getForm").submit();
    alert(headers);
  }
  </code></pre>
  
  <p>Google App Script:</p>
  
  <pre><code>function doGet(e) {
  //Trying To: Get headers from sheetID and then return to app, then have correct labels for the inputs, then use POST to post.
  var ss = SpreadsheetApp.openById(ScriptProperties.getProperty('active'));
  var sheet = ss.getSheetByName(e.parameter["sheetGetID"]);
  
  //Return the first 3 cells, A1:C1,
  var headers = sheet.getRange(1,1,1,sheet.getLastColumn()).getValues()[0];
  return ContentService.createTextOutput(JSON.stringify(headers))
  .setMimeType(ContentService.MimeType.JSON);
  }
  </code></pre>
  
  <p>I'm getting a JSON object returned but it's just a text output. My question is how would/could I get the JSON returned and stored as the headers variable?</p>