title: Pulling data from Google Chat into Spreadsheet
body: <p>I'm trying to pull data from google chat into a spreadsheet but I only need to pull the messages from one Space. I found a script to pull all chat messages but how can I specify which Space to pull from?</p>
  <pre><code>function getChats() {
    var sheet = SpreadsheetApp.getActiveSheet();
  
    sheet.getRange(1, 1).setValue(&quot;Date&quot;);
    sheet.getRange(1, 2).setValue(&quot;Subject&quot;);
    sheet.getRange(1, 3).setValue(&quot;Body&quot;);
    var row = 2;
    
    var chats = GmailApp.getChatThreads();
    var chat_count = chats.length;
    
    for (var i = 0; i &lt; chat_count; i++) {
     var count = chats[i].getMessageCount();
     var messages = chats[i].getMessages();
      
      for (var j = 0; j &lt; count; j++) {
        var chat_date = messages[j].getDate();
        var subject = messages[j].getSubject();
        var body = messages[j].getBody();
        sheet.getRange(row, 1).setValue(chat_date);
        sheet.getRange(row, 2).setValue(subject);
        sheet.getRange(row, 3).setValue(body);
        row++;
      }
      
    }
    Browser.msgBox(&quot;All done!&quot;);
  }
  </code></pre>