title: Private REST API connection Power BI (M - Power Query)
body: <p>I'd like to connect powerbi with client private Rest APi. So, I've been trying to write the code in M in order to do it, but I am not an expert in M language.</p>
  <p>This is what I've tried to generarte the Bearer Token inside Power bi. Can you help me with the code?</p>
  <pre><code>  let
      url = &quot;https://openid-provider.crearesistemas.com.br/auth/v1/token?lang=pt-BR&quot;,
      body  = &quot;{ &quot;&quot;client_id&quot;&quot;: &quot;&quot;*****&quot;&quot;,  &quot;&quot;client_secret&quot;&quot;: &quot;&quot;*****&quot;&quot;, &quot;&quot;grant_type&quot;&quot;: &quot;&quot;client_credentials&quot;&quot;}&quot;,
  
      tokenResponse = Json.Document(Web.Contents(url,
      [Headers = [#&quot;Authorization&quot;=&quot;Basic Auth&quot;, #&quot;Content-Type&quot;=&quot;application/json&quot;
      ],
       Content = Text.ToBinary(body)
      ] 
      )),
      AccessToken = tokenResponse[access_token],
      AccessTokenHeader = &quot;Bearer &quot; &amp; AccessToken
  in 
  AccessTokenHeader 
  </code></pre>
  <p>I don't know what I've done wrong.
  It shows the following error: &quot;DataSource.Error&quot; &quot;DataSourceKind=Web&quot; &quot;DataSourcePath=https://openid-provider.crearesistemas.com.br/auth/v1/token&quot;</p>
  <p>After generate the Bearer Token, I must use the 'get method' in order to request clients data from the api.<br />
  main_api_url: <a href="https://api.crearecloud.com.br/frotalog/basic-services/v3/" rel="nofollow noreferrer">https://api.crearecloud.com.br/frotalog/basic-services/v3/</a> ...
  Authorization: Bearer Token
  Json format</p>
  <p>I hope you guy can help me! Thanks in advance.</p>