title: How to trigger a Web App from another script?
body: <p>I deployed a Google Apps Script Web App which uses a service account to access the Google Directory. I deployed it that everyone has access to the app and that the app runs under the user executing it.</p>
  <p>I would like to trigger this web app by calling the POST trigger from another app script which is part of a Google form. Something like this:</p>
  <pre><code>function onPost(){
  var data = {
  'name': 'Bob Smith',
  'age': 35,
  'pets': ['fido', 'fluffy']
  };
  var options = {
   'method' : 'post',
   'contentType': 'application/json',.
   'payload' : JSON.stringify(data)
  };
  var resp = UrlFetchApp.fetch('https://script.google.com/a/my.domain.com/m.../exec', options);
  
  }
  </code></pre>
  <p>However, I get back:</p>
  <blockquote>
  <p>Exception: Request failed for <a href="https://script.google.com" rel="nofollow noreferrer">https://script.google.com</a> returned code 401.</p>
  </blockquote>
  <p>When I try to use the GET trigger with some query parameters the response back looks like a google sign in page.</p>
  <p>How can I trigger my web app from another app script all in the same domain?</p>
  <hr />
  <p>Updated code with token:</p>
  <pre><code>function onPost(){
  var token = ScriptApp.getOAuthToken();
  var data = {
  'name': 'Bob Smith',
  'age': 35,
  'pets': ['fido', 'fluffy']
  };
  var options = {
   'headers':'Bearer '+token,
   'method' : 'post',
   'contentType': 'application/json',.
   'payload' : JSON.stringify(data)
  };
  var resp = UrlFetchApp.fetch('https://script.google.com/a/my.domain.com/m.../exec', options);
  
  }
  </code></pre>