title: How to have app send message to Microsoft Teams via Graph API?
body: <p>I want to be able to use the graph API to get a list of channels &amp; teams, then have the app send an update to the appropriate channel without the user having to interact with MS Teams.  Looking around I see a lot of posts saying this isn't possible yet, but <a href="https://support.monday.com/hc/en-us/articles/360010359819-Microsoft-Teams-Integration?source=search" rel="nofollow noreferrer">Monday.com</a> and <a href="https://www.smartsheet.com/marketplace/apps/microsoft-teams" rel="nofollow noreferrer">Smartsheet</a> seem to be doing this. Monday.com even specifies its using the beta api and <em>neither</em> are using connectors.</p>
  
  <p>I attempted to do use the api <code>POST /teams/{id}/channels/{id}/messages</code> after authenticating via the way <a href="https://docs.microsoft.com/en-us/graph/auth-v2-service" rel="nofollow noreferrer">shown in this documentation</a></p>
  
  <p>First Call for <code>adminconsent</code></p>
  
  <p><code>https://login.microsoftonline.com/organizations/v2.0/adminconsent?&amp;client_id={botID}&amp;response_type=code&amp;redirect_uri=https://myoauthCallback&amp;scope=offline_access User.ReadWrite.All Group.ReadWrite.All</code></p>
  
  <p>After that returns I do an immediate call to get an access token, the above call doesn't seem to return anything I need to put into this request.</p>
  
  <p><code>POST =&gt; /organizations/oauth2/v2.0/token</code> </p>
  
  <p><code>body = client_id={botId}&amp;scope=https%3A%2F%2Fgraph.microsoft.com%2F.default&amp;client_secret={secret}&amp;grant_type=client_credentials</code></p>
  
  <p>I set the permissions in <code>https://portal.azure.com/#blade/</code> for the bot to have the same scope as the first request above. Here it doesn't like the scope passed in the same way so I set it to <code>default</code></p>
  
  <p>I then take the <code>access_token</code> that is returned and attempt the call to <code>POST</code> a message to the channel.</p>
  
  <p>URL: <code>/teams/{TEAM_ID}/channels/{CHANNEL_ID}/messages</code></p>
  
  <p>body: <code>{
          subject: 'test subj',
          body: { contentType: 'text', content: 'Test message from app' },
        }</code></p>
  
  <p>This results in an error</p>
  
  <p><code>statusCode: 401, code: 'UnknownError', message: ''</code></p>
  
  <p>So how do I get the same functionality of these other apps so I can send a message directly to teams without setting up a connector?</p>