<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: 401 when accessing any Power BI API endpoints in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/401-when-accessing-any-Power-BI-API-endpoints/m-p/336493#M9954</link>
    <description>&lt;P&gt;I found something that work and documented it (with code) here:&amp;nbsp;&lt;A href="https://bitbucket.org/omnistream/powerbi-api-example" target="_blank"&gt;https://bitbucket.org/omnistream/powerbi-api-example&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully it would help other people in need!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's not entirely satisfying: I'm notably not too sure why I should use this authentication endpoint instead of the one I found in other documentation, nor why I have to use a username/password on top of the app credentials, especially since it's not a super secure way to do it; I'm concerned it may get deprecated in the future. But it works.&lt;/P&gt;</description>
    <pubDate>Thu, 11 Jan 2018 09:27:26 GMT</pubDate>
    <dc:creator>eprochasson</dc:creator>
    <dc:date>2018-01-11T09:27:26Z</dc:date>
    <item>
      <title>401 when accessing any Power BI API endpoints</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/401-when-accessing-any-Power-BI-API-endpoints/m-p/335613#M9927</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to&amp;nbsp;access Power BI API in the goal to ultimately embed dashboards for my customers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I manage to generate an access token (which I assume valid: if I put wrong credentials, it fails to generate the token). I created a Power BI App using the wizard at &lt;A href="https://dev.powerbi.com/apps" target="_blank"&gt;https://dev.powerbi.com/apps&lt;/A&gt;. However, whatever I do, I get a 401 http error when talking to the API. Typically, the endpoint&amp;nbsp;&lt;SPAN&gt;&lt;A href="https://api.powerbi.com/v1.0/myorg/groups" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/groups&lt;/A&gt; doesn't require any parameter. I set the header as indicated, using the access&amp;nbsp;token.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;FWIW, I'm using the Python ADAL library to generate the access token (using application certificate -- the values given by the wizard at &lt;A href="https://dev.powerbi.com/apps" target="_blank"&gt;https://dev.powerbi.com/apps&lt;/A&gt;), then the requests library for simple http connection; my point being: I don't think it's a programming error, here's the code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;get_access_token&lt;/SPAN&gt;(&lt;SPAN&gt;self&lt;/SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;    context = adal.&lt;SPAN&gt;AuthenticationContext&lt;/SPAN&gt;(&lt;BR /&gt;        &lt;SPAN&gt;self&lt;/SPAN&gt;.authority_url + &lt;SPAN&gt;'/' &lt;/SPAN&gt;+ &lt;SPAN&gt;self&lt;/SPAN&gt;.tenant&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;validate_authority&lt;/SPAN&gt;=&lt;SPAN&gt;True&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;api_version&lt;/SPAN&gt;=&lt;SPAN&gt;None&lt;/SPAN&gt;)&lt;BR /&gt;    token = context.&lt;SPAN&gt;acquire_token_with_client_credentials&lt;/SPAN&gt;(&lt;SPAN&gt;self&lt;/SPAN&gt;.resource&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;self&lt;/SPAN&gt;.application_id&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;self&lt;/SPAN&gt;.application_key)&lt;BR /&gt;    &lt;SPAN&gt;return &lt;/SPAN&gt;token[&lt;SPAN&gt;'accessToken'&lt;/SPAN&gt;]&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;make_headers&lt;/SPAN&gt;(&lt;SPAN&gt;self&lt;/SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;    &lt;SPAN&gt;return &lt;/SPAN&gt;{&lt;BR /&gt;        &lt;SPAN&gt;'Content-Type'&lt;/SPAN&gt;: &lt;SPAN&gt;'application/json; charset=utf-8'&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;BR /&gt;&lt;/SPAN&gt;        &lt;SPAN&gt;'Authorization'&lt;/SPAN&gt;: &lt;SPAN&gt;"Bearer {}"&lt;/SPAN&gt;.&lt;SPAN&gt;format&lt;/SPAN&gt;(&lt;SPAN&gt;self&lt;/SPAN&gt;.&lt;SPAN&gt;get_access_token&lt;/SPAN&gt;())&lt;BR /&gt;    }&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;def &lt;/SPAN&gt;&lt;SPAN&gt;get_groups&lt;/SPAN&gt;(&lt;SPAN&gt;self&lt;/SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;BR /&gt;    endpoint = &lt;SPAN&gt;"https://api.powerbi.com/v1.0/myorg/groups"&lt;BR /&gt;&lt;/SPAN&gt;    headers = &lt;SPAN&gt;self&lt;/SPAN&gt;.&lt;SPAN&gt;make_headers&lt;/SPAN&gt;()&lt;BR /&gt;    &lt;SPAN&gt;return &lt;/SPAN&gt;requests.&lt;SPAN&gt;get&lt;/SPAN&gt;(endpoint&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;headers&lt;/SPAN&gt;=headers)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Calling `get_groups`&amp;nbsp;returns a 401 http error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The generated header looks something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Authorization: Bearer eyJ...pBQ&lt;/PRE&gt;&lt;P&gt;which seems fine to me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- The App in the AD tenant has the right permission (generated by the wizard).&lt;/P&gt;&lt;P&gt;- I use &lt;A href="https://login.windows.net" target="_blank"&gt;https://login.windows.net&lt;/A&gt; for the "authority url", but that doesn't seem to be a problem anyway since the access token is generated properly&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I followed the tutorial here&amp;nbsp;&lt;A href="https://docs.microsoft.com/en-us/power-bi/developer/embedding-content" target="_blank"&gt;https://docs.microsoft.com/en-us/power-bi/developer/embedding-content&lt;/A&gt; and tried pretty much everything I could Google to solve my problem, with no luck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit: the error is for any endpoints I tried, not only "groups".&lt;/P&gt;&lt;P&gt;I also tried with command line curl:&lt;/P&gt;&lt;PRE&gt;curl -v -X POST -H 'Authorization: Bearer eyJ...zA' "https://api.powerbi.com/v1.0/myorg/groups" -H 'Content-Length: 0'&lt;/PRE&gt;&lt;P&gt;and get:&lt;/P&gt;&lt;PRE&gt;&amp;lt; HTTP/1.1 401 Unauthorized
&amp;lt; Cache-Control: no-store, must-revalidate, no-cache
&amp;lt; Transfer-Encoding: chunked
&amp;lt; Content-Type: application/octet-stream
&amp;lt; Server: Microsoft-HTTPAPI/2.0 Microsoft-HTTPAPI/2.0
&amp;lt; Strict-Transport-Security: max-age=31536000; includeSubDomains
&amp;lt; X-Frame-Options: deny
&amp;lt; X-Content-Type-Options: nosniff
&amp;lt; RequestId: 7f8535e6-10ff-422b-8f81-a5cabb8b930b
&amp;lt; Date: Wed, 10 Jan 2018 09:05:20 GMT&lt;/PRE&gt;&lt;P&gt;as a response (so it doesn't seem to be a problem with my code). Note that if I put an wrong token (e.g.: if I remove some characters) I get a 403 error instead, which definitely makes me think this is not a problem with how I forge the query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Additional Edit: the permission for the App in AD, I granted everything to be sure (I also try only granting what's required, and tried various combination):&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot_20180111_081530.png" style="width: 600px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/77139i40BC2CD233AE70C3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot_20180111_081530.png" alt="Screenshot_20180111_081530.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Screenshot_20180111_081542.png" style="width: 600px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/77140iFC222F4EEB9E11EB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot_20180111_081542.png" alt="Screenshot_20180111_081542.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They are saved and granted. I also double-checked that the credentials I use to generate the access token correspond to this app.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 00:17:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/401-when-accessing-any-Power-BI-API-endpoints/m-p/335613#M9927</guid>
      <dc:creator>eprochasson</dc:creator>
      <dc:date>2018-01-11T00:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: 401 when accessing any Power BI API endpoints</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/401-when-accessing-any-Power-BI-API-endpoints/m-p/336374#M9944</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/51493"&gt;@eprochasson&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What App Type did you choose when you&amp;nbsp;&lt;SPAN&gt;register your application with the Power BI App Registration Tool?&amp;nbsp;&lt;/SPAN&gt;The App type selection will depend on the type of application you are using. So you may need to choose&amp;nbsp;&lt;STRONG class=""&gt;Native app&amp;nbsp;&lt;/STRONG&gt;in your scenario.&lt;/P&gt;
&lt;UL&gt;
&lt;LI class=""&gt;Use&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Server-side Web app&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;for web apps or web APIs.&lt;/LI&gt;
&lt;LI class=""&gt;Use&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG class=""&gt;Native app&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;for apps that run on client devices.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG class=""&gt;&lt;EM class=""&gt;You will also choose *&lt;/EM&gt;Native app&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if you are embedding content for your customers regardless of what the actual application is. Even for web applications.***&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;As I'm not familiar with&amp;nbsp;&lt;SPAN&gt;Python ADAL library and the command line&amp;nbsp;you're using, could you try using &lt;A href="https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en" target="_self"&gt;Postman&lt;/A&gt; like below with a new created access token(either with your code or Postman) to see if the Get Group api works, in order to narrow down this issue?&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://community.fabric.microsoft.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="post1.PNG" style="width: 600px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/77170iD5FCA0707B12523A/image-size/large?v=v2&amp;amp;px=999" role="button" title="post1.PNG" alt="post1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 06:37:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/401-when-accessing-any-Power-BI-API-endpoints/m-p/336374#M9944</guid>
      <dc:creator>v-ljerr-msft</dc:creator>
      <dc:date>2018-01-11T06:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: 401 when accessing any Power BI API endpoints</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/401-when-accessing-any-Power-BI-API-endpoints/m-p/336376#M9945</link>
      <description>&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used Web App. Native app doesn't allow to get a secret key for the app (apparently). I must admit the line you quote (that I read before) is quite confusing. Note that I tried with Native App before, with no success either.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;replicated (and included) the examples using Curl, which is similar to Postman.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I may have found a workaround using REST only, I'll confirm and post a solution here when it's ready. It appears the authentication method is wrong, it works if I use both application credentials AND user credentials, and&amp;nbsp;negotiate the access token with&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;https://login.microsoftonline.com/common/oauth2/token&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;https://login.microsoftonline.com/&amp;lt;tenant id&amp;gt;/oauth2/token&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;as indicated in the documentation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;None of that is properly documented so I can't explain why, it just seems to work. It works using a "Web App", and default permissions.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 06:43:27 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/401-when-accessing-any-Power-BI-API-endpoints/m-p/336376#M9945</guid>
      <dc:creator>eprochasson</dc:creator>
      <dc:date>2018-01-11T06:43:27Z</dc:date>
    </item>
    <item>
      <title>Re: 401 when accessing any Power BI API endpoints</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/401-when-accessing-any-Power-BI-API-endpoints/m-p/336493#M9954</link>
      <description>&lt;P&gt;I found something that work and documented it (with code) here:&amp;nbsp;&lt;A href="https://bitbucket.org/omnistream/powerbi-api-example" target="_blank"&gt;https://bitbucket.org/omnistream/powerbi-api-example&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hopefully it would help other people in need!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's not entirely satisfying: I'm notably not too sure why I should use this authentication endpoint instead of the one I found in other documentation, nor why I have to use a username/password on top of the app credentials, especially since it's not a super secure way to do it; I'm concerned it may get deprecated in the future. But it works.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jan 2018 09:27:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/401-when-accessing-any-Power-BI-API-endpoints/m-p/336493#M9954</guid>
      <dc:creator>eprochasson</dc:creator>
      <dc:date>2018-01-11T09:27:26Z</dc:date>
    </item>
  </channel>
</rss>

