title: How do I retrieve a bearer token from a service in Power BI?
body: <p>I am attempting to call a web API-- say, <code>https://myresources/getresources</code>. This call requires an API Key, resourcesApiKey and a bearer token. The token must be acquired from another service, <code>https://mytokenservice/jwt</code>. It requires an API key, tokenServiceApiKey.</p>
  <p>I'm able to get my resource data by manually accessing the token service and entering values, but I'd like to have Power BI take care of all this for me. I read something about this <a href="https://stackoverflow.com/questions/60056709/where-do-i-save-token-in-power-bi-web-connection">here</a>, but this seems to apply to a static token. Ours changes, so I need to actually call out to this service.</p>
  <p>So, what I'm trying to do is this:</p>
  <ol>
  <li>Save a token service url and API key with my report. When the report is run, Power BI should use the url and key to retrieve a bearer token.</li>
  <li>Save a resources API url and api key with my report. Apply the bearer token retrieved in step 1, along with the resources API key to calls made to the resource API url to retrieve the data I'm really after.</li>
  </ol>
  <p>I think the approach described <a href="https://blog.crossjoin.co.uk/2014/03/26/working-with-web-services-in-power-query/" rel="nofollow noreferrer">here</a> applies, but I can't get it to work. Here's what I most recently tried using the Power BI advanced editor:</p>
  <ul>
  <li><p>I created a parameter in Power BI using Manage Parameters, then used Advanced Editor, I entered the following:</p>
  <p>Web.Content(
  &quot;<code>https://mytokenservice/jwt</code>&quot;,
  [
  ApiKeyName=&quot;tokenServiceApiKey&quot;
  ]
  )</p>
  </li>
  </ul>
  <p>I also created Power BI parameters for tokenServiceApiKey and resourcesApiKey that contain the key for each.</p>
  <p>When I clicked &quot;Done&quot; in the Advanced Editor, though, it automatically generated some code around what I'd written, so that it now reads,</p>
  <pre><code>Html.Table(Web.Content(&quot;https://mytokenservice/jwt&quot;,[ApiKeyName=&quot;tokenServiceApiKey&quot;]), {})
  </code></pre>
  <p>What appears in the editor is a table icon containing no data. I should be getting a string back. I don't know where to go from here and am having trouble finding answers online.</p>
  <p>Is there anyway to accomplish what I'm after?</p>
  <p>I probably haven't explained it very well, so please ask questions if you need more information or clarification.</p>