title: Form Submit google cloud print
body: <p>I could use some help with creating a script when a Google Form is submitted.  </p>
  
  <p>Once the form submitted, the script automatically prints a Google Spreadsheet to a Google Cloud-based printer without bringing up the print dialog window. </p>
  
  <p>I've read through <a href="https://developers.google.com/cloud-print/docs/gadget" rel="nofollow">Google Cloud Print Info</a> </p>
  
  <p>The idea behind the script is simple:</p>
  
  <ul>
  <li>User fills out form</li>
  <li>Form is then submitted</li>
  <li>Script updates cells with information user put in</li>
  <li>Script then prints to google cloud printer</li>
  <li>Shipping label is ready  </li>
  </ul>
  
  <p>The below script will print a ticket but how do i add the printer capabilities to the POST request?</p>
  
  <p>The code I have so far:</p>
  
  <pre><code>function onsubmit(e) {
  var pid = "123456789"; //place printer id here
  var sheetid = "123456789"; //place sheet id here
  var ss = SpreadsheetApp.getActiveSpreadsheet();  
  var info = ss.getSheetByName('Form responses 1');  
  var lastRow = info.getLastRow();  
  var sheet = SpreadsheetApp.setActiveSheet(ss.getSheetByName('TICKET'))  
  
  authorize();
  var url = "https://www.google.com/cloudprint/submit?printerid="+pid+"&amp;contentType=google.spreadsheet&amp;content="+sheetid+"&amp;title=PrintingTicket";
  var options = {
    method: "post",
    oAuthServiceName : "print",
    oAuthUseToken : "always"
     };
  info.hideSheet();
  var response = UrlFetchApp.fetch(url, options);
  return Utilities.jsonParse(response.getContentText());
  }
  
  function authorize() {
  var oauthConfig = UrlFetchApp.addOAuthService("print");
  var scope = "https://www.googleapis.com/auth/cloudprint";
  oauthConfig.setConsumerKey("anonymous");
  oauthConfig.setConsumerSecret("anonymous");
  oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
  oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken");    
  oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");  
  }
  </code></pre>