title: How do I send a custom header using Power BI when Windows Authorization is required?
body: <p>I am attempting to use Power BI (Power Query) to access a bearer token API that uses Windows Authentication and requires an api key header. The problem I'm running into is that Power BI accepts only certain headers. When I attempt to include my organization's &quot;api-key&quot; header, I receive the following error message:</p>
  <pre><code>Expression.Error: The 'api-key' header is only supported when connecting anonymously. These headers can be used with all authentication types: Accept, Accept-Charset, Accept-Encoding, Accept-Language, Cache-Control, Content-Type, If-Modified-Since, Prefer, Range, Referer
  </code></pre>
  <p>The code I'm using looks something like this, though I've tried several variations:</p>
  <pre><code>let
  
      securityTokenServiceUrl = &quot;https://mysecurityservice&quot;,
      myApiKey = &quot;123456789&quot;,
      securityHeader = &quot;{
          &quot;&quot;accept&quot;&quot;: &quot;&quot;text/plain&quot;&quot;,
          &quot;&quot;api-key&quot;&quot;: &quot;&quot;&quot;&amp; myApiKey &amp; &quot;&quot;&quot;
      }&quot;,
      tokenResponse = Json.Document(Web.Contents(securityTokenServiceUrl, [
          Headers = Json.Document(securityHeader)
          ])),
      token = tokenResponse[access_token]
  
  in
      token
  </code></pre>
  <p>I've done a lot of looking around, but can only find suggestions on how to do this with Anonymous authorization, not with Windows Auth, as I need. I tried using a custom data connector as suggested <a href="https://stackoverflow.com/questions/63400612/how-do-i-retrieve-a-bearer-token-from-a-service-in-power-bi">here</a>, but cannot seem to get it working. Is there any way to get around this restriction and pass along my api key header as described above?</p>