<?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 Error while creating Access token for Power BI REST API in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237057#M42674</link>
    <description>&lt;P&gt;I was trying to generate an access token for Power BI REST API.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was following the way that is described in this answer.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Developer/Power-BI-REST-API-using-postman-generate-embed-token/m-p/310153#M9157" target="_blank" rel="noopener"&gt;https://community.powerbi.com/t5/Developer/Power-BI-REST-API-using-postman-generate-embed-token/m-p/310153#M9157&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I am getting the following error -&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"error"&lt;/SPAN&gt;&lt;SPAN&gt;:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"invalid_grant"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"error_description"&lt;/SPAN&gt;&lt;SPAN&gt;:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"AADSTS50126:&amp;nbsp;Error&amp;nbsp;validating&amp;nbsp;credentials&amp;nbsp;due&amp;nbsp;to&amp;nbsp;invalid&amp;nbsp;username&amp;nbsp;or&amp;nbsp;password.\r\nTrace&amp;nbsp;ID:&amp;nbsp;0237bedd-9747-47d3-bc4d-27bdb1fc5a00\r\nCorrelation&amp;nbsp;ID:&amp;nbsp;e47b45a3-f479-4d09-933d-e6dfeae24ea8\r\nTimestamp:&amp;nbsp;2023-05-16&amp;nbsp;06:37:21Z"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"error_codes"&lt;/SPAN&gt;&lt;SPAN&gt;:&amp;nbsp;[&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;50126&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;LI-MESSAGE title="power BI rest API with python" uid="1953492" url="https://community.powerbi.com/t5/Desktop/power-BI-rest-API-with-python/m-p/1953492#U1953492" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&amp;nbsp;&lt;LI-MESSAGE title="REST API Generate access token" uid="3172021" url="https://community.powerbi.com/t5/Developer/REST-API-Generate-access-token/m-p/3172021#U3172021" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Tue, 16 May 2023 06:47:07 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-05-16T06:47:07Z</dc:date>
    <item>
      <title>Error while creating Access token for Power BI REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237057#M42674</link>
      <description>&lt;P&gt;I was trying to generate an access token for Power BI REST API.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was following the way that is described in this answer.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Developer/Power-BI-REST-API-using-postman-generate-embed-token/m-p/310153#M9157" target="_blank" rel="noopener"&gt;https://community.powerbi.com/t5/Developer/Power-BI-REST-API-using-postman-generate-embed-token/m-p/310153#M9157&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I am getting the following error -&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"error"&lt;/SPAN&gt;&lt;SPAN&gt;:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"invalid_grant"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"error_description"&lt;/SPAN&gt;&lt;SPAN&gt;:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"AADSTS50126:&amp;nbsp;Error&amp;nbsp;validating&amp;nbsp;credentials&amp;nbsp;due&amp;nbsp;to&amp;nbsp;invalid&amp;nbsp;username&amp;nbsp;or&amp;nbsp;password.\r\nTrace&amp;nbsp;ID:&amp;nbsp;0237bedd-9747-47d3-bc4d-27bdb1fc5a00\r\nCorrelation&amp;nbsp;ID:&amp;nbsp;e47b45a3-f479-4d09-933d-e6dfeae24ea8\r\nTimestamp:&amp;nbsp;2023-05-16&amp;nbsp;06:37:21Z"&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;"error_codes"&lt;/SPAN&gt;&lt;SPAN&gt;:&amp;nbsp;[&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;50126&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;LI-MESSAGE title="power BI rest API with python" uid="1953492" url="https://community.powerbi.com/t5/Desktop/power-BI-rest-API-with-python/m-p/1953492#U1953492" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&amp;nbsp;&lt;LI-MESSAGE title="REST API Generate access token" uid="3172021" url="https://community.powerbi.com/t5/Developer/REST-API-Generate-access-token/m-p/3172021#U3172021" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 16 May 2023 06:47:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237057#M42674</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-16T06:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: Error while creating Access token for Power BI REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237090#M42675</link>
      <description>&lt;P&gt;Hey&amp;nbsp;@Anonymous&lt;/a&gt;, from the error descriptions looks like you are using an invalid username or password. Can you please provide the complete description of the request you are using (endpoint, etc)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I recall you that if you are authorizing with username/password (instead of service principal), you have to set "grant_type" to value "password" (instead of "client_credentials).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Wait for you reply,&lt;/P&gt;&lt;P&gt;Luigi&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 07:02:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237090#M42675</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-16T07:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: Error while creating Access token for Power BI REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237127#M42678</link>
      <description>&lt;P&gt;I did put the grant_type as password. My request is as following.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;POST &lt;A href="https://login.windows.net/common/oauth2/token" target="_blank"&gt;https://login.windows.net/common/oauth2/token&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Request body&amp;nbsp;&lt;/P&gt;&lt;P&gt;grant_type : password&lt;/P&gt;&lt;P&gt;username :&amp;nbsp; **********&lt;/P&gt;&lt;P&gt;password : ***********&lt;/P&gt;&lt;P&gt;client_id : ********* (client id in the app I created for using REST API)&lt;/P&gt;&lt;P&gt;resource :&amp;nbsp;&lt;SPAN&gt;&lt;A href="https://analysis.windows.net/powerbi/api" target="_blank"&gt;https://analysis.windows.net/powerbi/api&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 07:18:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237127#M42678</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-16T07:18:20Z</dc:date>
    </item>
    <item>
      <title>Re: Error while creating Access token for Power BI REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237139#M42679</link>
      <description>&lt;P&gt;Hey&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp;I cannot spot mistakes in you request. My guess would be that you are somehow using an invalid username or password. I therefore suggest either:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Waiting for someone else opinion&lt;/P&gt;&lt;P&gt;- Authenticate with service principal. Generate a secret for the app you alredy have in your AD and then use the following request:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;POST https://login.microsoftonline.com/{{Tenant ID}}/oauth2/v2.0/token
client_id : your client_id
client_secret: the client secret you just generated
grant_type: client_credentials
scope: https://analysis.windows.net/powerbi/api/.default&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Be careful, once you generate your app secret, save it, because you will not be able to retreive it again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me know if this solution works for you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 07:26:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237139#M42679</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-16T07:26:17Z</dc:date>
    </item>
    <item>
      <title>Re: Error while creating Access token for Power BI REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237167#M42680</link>
      <description>&lt;P&gt;@Anonymous&lt;/a&gt;&amp;nbsp;I just found this article that might explain the issue you are facing&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/azure/hdinsight/domain-joined/domain-joined-authentication-issues" target="_blank"&gt;Authentication issues in Azure HDInsight | Microsoft Learn&lt;/A&gt;. In particular&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="lmarangio_0-1684222440159.png" style="width: 400px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/915230i60B01511BA2EDDC8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="lmarangio_0-1684222440159.png" alt="lmarangio_0-1684222440159.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Hence either you set up this policy or you use Service Principal as authorization method:)&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 07:34:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237167#M42680</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-16T07:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Error while creating Access token for Power BI REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237310#M42681</link>
      <description>&lt;P&gt;Hi&amp;nbsp;@Anonymous&lt;/a&gt;&amp;nbsp; Thank you. This method is working and I am generating an access token.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I still have some issues though, that is, when I use this token as Bearer token for REST API, I am getting a 401 Error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the request that I tried with the generated Access Token&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;EM&gt;access_token=****************************&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;bearertoken=access_token&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;gatewayId=*********&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;datasourceId=*************&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;url=f"&lt;A href="https://api.powerbi.com/v1.0/myorg/gateways/{gatewayId}/datasources/{datasourceId" target="_blank"&gt;https://api.powerbi.com/v1.0/myorg/gateways/{gatewayId}/datasources/{datasourceId&lt;/A&gt;}"&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;Headers={&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; "Authorization": f"Bearer {bearertoken}"&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;EM&gt;}&lt;/EM&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;EM&gt;response=requests.request("GET", url=url, headers=Headers)&lt;/EM&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;EM&gt;print(response.status_code, response.content)&lt;/EM&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Result comes as -&lt;STRONG&gt; 401 b''&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Please let me know if the access token I generated by the method you suggested isn't the correct bearer token. If you know how I can generate a bearer token for this purpose, I appreciate your help.&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 16 May 2023 08:53:22 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237310#M42681</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-16T08:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Error while creating Access token for Power BI REST API</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237405#M42682</link>
      <description>&lt;P&gt;Hey&amp;nbsp;@Anonymous&lt;/a&gt;,&amp;nbsp;I am happy that now is working! You can be sure this is the right way to generate a token to authorize PBI REST API.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem here is that you have to setup the right permission in PBI. As you can see from the documentation: &lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/gateways/get-datasource" target="_blank"&gt;Gateways - Get Datasource - REST API (Power BI Power BI REST APIs) | Microsoft Learn&lt;/A&gt; there are permission, scope and limitations that you have to take into account.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I never worked with datasource and gateway in PBI so I do not in this specific situation how to set up this permission, but that's the problem you have to solve.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suggest you to accept the previous solution and open another post, since this is not anymore about an Access Token. I am sure community will help you in setting up the right permission if you will have problems in doing so.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 16 May 2023 09:38:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Error-while-creating-Access-token-for-Power-BI-REST-API/m-p/3237405#M42682</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-05-16T09:38:59Z</dc:date>
    </item>
  </channel>
</rss>

