title: Apps script write script for connect html page with spreadsheet
body: <p>friends.</p>
  <p>I'm trying to work with video <a href="https://www.youtube.com/watch?v=VPI27L_fQC4&amp;list=PLRmEk9smitaVGAAhgU0Pdc2sEs7yxDrEk&amp;index=1" rel="nofollow noreferrer">https://www.youtube.com/watch?v=VPI27L_fQC4&amp;list=PLRmEk9smitaVGAAhgU0Pdc2sEs7yxDrEk&amp;index=1</a></p>
  <p>I need to connect spreadsheet data with html-page outside of apps-scripts' project.</p>
  <p>At js-file for it for html-project I wrote this</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function addGS(){
  
    const url = "https://script.google.com/macros/s/AKfycbyHHYfQ9o25lqE_TUFK01-12wYGdI3_TkcDgBpZxbAAupak3lxXFH9wpbzAwzNXWxTw7w/exec";
      fetch(url, {
          method: 'POST', // *GET, POST, PUT, DELETE, etc.
          mode: 'cors', // no-cors, *cors, same-origin
          cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
          credentials: 'omit', // include, *same-origin, omit
          headers: {
            'Content-Type': 'application/json'
            // 'Content-Type': 'application/x-www-form-urlencoded',
          },
          redirect: 'follow', // manual, *follow, error
          //referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
          body: JSON.stringify({name: "olivia"}) // body data type must match "Content-Type" header
        });
  
        document.getElementById("send").addEventListener("Click", addGS);
  
  }</code></pre>
  </div>
  </div>
  </p>
  <p>in apps script I wrote this:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function doPost(e){
  
    const body = e.postData.contents;
    const bodyJSON = JSON.parse(body);
    const ss = SpreadsheetApp.getActiveSpreadsheet();
    const ws = ss.getSheetByName("PUTAWAY_TO");
    ws.appendRow([bodyJSON.name]);
  }</code></pre>
  </div>
  </div>
  </p>
  <p>but when I start script in apps script doPost like in video on 13:50, I get mistake at e.postData.contents &quot;TypeError: Cannot read property 'postData' of undefined&quot;. Can you help me, what I forgot to do? May be I need to include some API or module?
  Thank you for help!</p>
  <p>my last javascript from html by help Tanaike:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function addGS(){
    const url = "https://script.google.com/macros/s/AKfycbzBO2Z2G8_i8USGMKMTEBJNgGF1pANcXdQfSS9PbshtjgTiMZloegeXz3XVUBvotziMmg/exec";
    fetch(url, {
      method: 'POST',
      mode: 'no-cors', // no-cors, *cors, same-origin
      body: JSON.stringify({name: "olivia"})
    })
    .then((res) =&gt; res.text())
    .then((res) =&gt; console.log(res));
  }
  
  document.getElementById("send").addEventListener("click", addGS);</code></pre>
  </div>
  </div>
  </p>
  <p>and last apps-script thanks to Tanaike:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function doPost(e){
    const body = e.postData.contents;
    const bodyJSON = JSON.parse(body);
    const ss = SpreadsheetApp.getActiveSpreadsheet();
    const ws = ss.getSheetByName("PUTAWAY_TO");
    ws.appendRow([bodyJSON.name]);
    return ContentService.createTextOutput("ok");
  }</code></pre>
  </div>
  </div>
  </p>
  <p>Javascript for last question about export object to spreadsheet:</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function addGS(){
    var userInfo = {
        login: "Dima",
        sscc: "233425236523",
        place: "dsdsds"
    }
    const url = "https://script.google.com/macros/s/AKfycbw60bZu-BQ0kJ7NMkohJwZLGFHIN0cf5-Dkz-lq-Qeh9pkuDNaL/exec";
    fetch(url, {
      method: 'POST',
      body: JSON.stringify(userInfo)
    })
    .then((res) =&gt; res.text())
    .then((res) =&gt; console.log(res));
  }</code></pre>
  </div>
  </div>
  </p>