title: Send message to Google Chat using the REST API (Google example not working in 2020)
body: <p><em>Where do I even begin... (Google, why must you hurt me this way?)</em></p>
  <p><strong>Background Info</strong></p>
  <p>I have created a new chatbot <a href="https://developers.google.com/hangouts/chat/how-tos/bots-apps-script" rel="nofollow noreferrer">using Google Apps Script</a>, which receives messages from users in <a href="https://chat.google.com" rel="nofollow noreferrer">Google Chat</a> and responds <strong>synchronously</strong> with a single message (each message can only have one response from the chatbot).</p>
  <p>Now I need a way to send <strong>asynchronous</strong> messages so that the bot can send messages on its own, or send multiple separate responses at a time.</p>
  <p><strong>The problem</strong></p>
  <p>The <a href="https://developers.google.com/hangouts/chat/how-tos/rest-api" rel="nofollow noreferrer">Google Chat REST API</a> has a method to <a href="https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages/create" rel="nofollow noreferrer">create a message asynchronously</a>, <strong>but this method (<code>spaces.messages.create</code>) does not work! There are no working examples of this method from 2020.</strong></p>
  <p>Here is Google's <a href="https://developers.google.com/hangouts/chat/how-tos/bots-apps-script#async_messages" rel="nofollow noreferrer">example code</a> for creating a message using the REST API.</p>
  <p>The problem is that in their example, the <code>SCOPE</code> is set to <a href="https://www.googleapis.com/auth/chat.bot" rel="nofollow noreferrer">a URL that no longer exits</a>:</p>
  <pre><code>var SCOPE = 'https://www.googleapis.com/auth/chat.bot';
  </code></pre>
  <p>If you navigate to that URL, you will see this 404 error:</p>
  <pre><code>Not Found
  Error 404
  </code></pre>
  <p>Furthermore, if you check the <a href="https://developers.google.com/identity/protocols/oauth2/scopes" rel="nofollow noreferrer">list of available OAuth2 scopes</a>, you will notice that there are no scopes related to Hangouts <em>or</em> Chat, and there is no mention of the <code>chat.bot</code> the scope which was used in the example code.</p>
  <p><strong>What have I tried?</strong></p>
  <p>I have read through every question on StackOverflow that is related to this Chat API, plus every tutorial for the REST API.</p>
  <ul>
  <li>The official Apps Script tutorial from Google does not work because the <code>chat.bot</code> scope no longer exists:
  <ul>
  <li><a href="https://developers.google.com/hangouts/chat/how-tos/bots-apps-script#async_messages" rel="nofollow noreferrer">Async Messages using Apps Script</a></li>
  </ul>
  </li>
  <li>These StackOverflow solutions all make use of the same non-existant <code>chat.bot</code> scope:
  <ul>
  <li><a href="https://stackoverflow.com/questions/62674583/hangout-chatbot-send-private-message-without-event">Send private message without event</a></li>
  <li><a href="https://stackoverflow.com/questions/49855550/asynchronously-respond-in-new-hangout-chat-using-rest-api-without-using-google">Asynchronously Respond in new Hangout Chat using rest API</a></li>
  <li><a href="https://stackoverflow.com/questions/59798550/404-truncated-server-response-on-apps-script-bot">404 truncated server response on Apps Script Bot</a></li>
  </ul>
  </li>
  <li>This StackOverflow user says they were able to use the <code>chat</code> scope (i.e. <code>googleapis.com/auth/chat</code>), but that scope does not exist either:
  <ul>
  <li><a href="https://stackoverflow.com/questions/49353286/error-400-invalid-scope-https-www-googleapis-com-auth-chat-bot">Error 400: invalid_scope</a></li>
  </ul>
  </li>
  </ul>
  <p><strong>In conclusion</strong></p>
  <p>How to send messages <em>from</em> Google Apps Script <em>to</em> Google Chat using the <a href="https://developers.google.com/hangouts/chat/how-tos/rest-api" rel="nofollow noreferrer">Google Chat REST API</a>?</p>
  <p>It seems that Google's documentation is outdated, and none of the examples for this API work as of August 2020. They are either unaware that their REST API does not work, or they deprecated the REST API without telling anyone.</p>