<?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 Power BI API return 401 Unauthorized` response in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-return-401-Unauthorized-response/m-p/1084320#M23601</link>
    <description>&lt;P&gt;Hello Everybody,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem with a Power BI API&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First i get the Token:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;$url = 'https://login.windows.net/' . $directoryIdAzure . '/oauth2/token'
            /** @var GuzzleHttp\Client $client **/
            $response = $client-&amp;gt;post(
                $url,
                [
                    "headers" =&amp;gt; [
                        "Accept" =&amp;gt; "application/json"
                    ],
                    'form_params' =&amp;gt; [
                        'resource'      =&amp;gt; 'https://analysis.windows.net/powerbi/api',
                        'client_id'     =&amp;gt; $clientIdAzure,
                        'client_secret' =&amp;gt; $clientSecretAzure,
                        'grant_type'    =&amp;gt; 'client_credentials',
                        'username'      =&amp;gt; $user,
                        'password'      =&amp;gt; $pass,
                        'scope'         =&amp;gt; 'openid',
                    ]
                ]
            );

            $body = json_decode($response-&amp;gt;getBody()-&amp;gt;getContents(), true);

            $token = $body['access_token'];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After i need list all Workspaces using a token&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;            $client2 = new \GuzzleHttp\Client();
            $res = $client2-&amp;gt;request(
                'GET',
                'https://api.powerbi.com/v1.0/myorg/groups',
                [
                    'headers' =&amp;gt;
                    [
                        'Authorization' =&amp;gt; 'Bearer ' . $token,
                        'Accept' =&amp;gt; 'application/json',
                        'Content-type' =&amp;gt; 'application/json'
                    ]
                ]
            );

            $workspaces = json_decode($res-&amp;gt;getBody()-&amp;gt;getContents(), true);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Return this error for me:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;"&lt;SPAN class="sf-dump-str"&gt;Client error: `GET https://api.powerbi.com/v1.0/myorg/groups` resulted in a `401 Unauthorized` response&lt;/SPAN&gt;"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The permissions in the Azure it's OK:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 11 May 2020 14:54:34 GMT</pubDate>
    <dc:creator>marcio_fornari</dc:creator>
    <dc:date>2020-05-11T14:54:34Z</dc:date>
    <item>
      <title>Power BI API return 401 Unauthorized` response</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-return-401-Unauthorized-response/m-p/1084320#M23601</link>
      <description>&lt;P&gt;Hello Everybody,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem with a Power BI API&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First i get the Token:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;$url = 'https://login.windows.net/' . $directoryIdAzure . '/oauth2/token'
            /** @var GuzzleHttp\Client $client **/
            $response = $client-&amp;gt;post(
                $url,
                [
                    "headers" =&amp;gt; [
                        "Accept" =&amp;gt; "application/json"
                    ],
                    'form_params' =&amp;gt; [
                        'resource'      =&amp;gt; 'https://analysis.windows.net/powerbi/api',
                        'client_id'     =&amp;gt; $clientIdAzure,
                        'client_secret' =&amp;gt; $clientSecretAzure,
                        'grant_type'    =&amp;gt; 'client_credentials',
                        'username'      =&amp;gt; $user,
                        'password'      =&amp;gt; $pass,
                        'scope'         =&amp;gt; 'openid',
                    ]
                ]
            );

            $body = json_decode($response-&amp;gt;getBody()-&amp;gt;getContents(), true);

            $token = $body['access_token'];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After i need list all Workspaces using a token&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;            $client2 = new \GuzzleHttp\Client();
            $res = $client2-&amp;gt;request(
                'GET',
                'https://api.powerbi.com/v1.0/myorg/groups',
                [
                    'headers' =&amp;gt;
                    [
                        'Authorization' =&amp;gt; 'Bearer ' . $token,
                        'Accept' =&amp;gt; 'application/json',
                        'Content-type' =&amp;gt; 'application/json'
                    ]
                ]
            );

            $workspaces = json_decode($res-&amp;gt;getBody()-&amp;gt;getContents(), true);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Return this error for me:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;"&lt;SPAN class="sf-dump-str"&gt;Client error: `GET https://api.powerbi.com/v1.0/myorg/groups` resulted in a `401 Unauthorized` response&lt;/SPAN&gt;"&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The permissions in the Azure it's OK:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 May 2020 14:54:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-return-401-Unauthorized-response/m-p/1084320#M23601</guid>
      <dc:creator>marcio_fornari</dc:creator>
      <dc:date>2020-05-11T14:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI API return 401 Unauthorized` response</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-return-401-Unauthorized-response/m-p/1086030#M23623</link>
      <description>&lt;P&gt;I Solved my problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I change&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;'grant_type'    =&amp;gt; 'client_credentials',&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;to&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;'grant_type'    =&amp;gt; 'password',&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and&amp;nbsp;I had to disable&amp;nbsp;&lt;STRONG&gt;Security Defaults &lt;/STRONG&gt;in the Azure&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Azure Portal &amp;gt; Azure AD &amp;gt; Properties &amp;gt; Click on Manage Security Defaults link &amp;gt; Toggle Enable Security Defaults button to NO&lt;/STRONG&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I hope thats help anyone.&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 May 2020 13:16:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-return-401-Unauthorized-response/m-p/1086030#M23623</guid>
      <dc:creator>marcio_fornari</dc:creator>
      <dc:date>2020-05-12T13:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI API return 401 Unauthorized` response</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-return-401-Unauthorized-response/m-p/4034429#M54091</link>
      <description>&lt;P&gt;You also need to enable use of the Fabric API within the Developer settings of your Power BI tenant.&amp;nbsp; See ths link for details:&amp;nbsp;&amp;nbsp;&lt;A href="https://learn.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal" target="_blank"&gt;https://learn.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 10:22:05 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-API-return-401-Unauthorized-response/m-p/4034429#M54091</guid>
      <dc:creator>spatialcase</dc:creator>
      <dc:date>2024-07-10T10:22:05Z</dc:date>
    </item>
  </channel>
</rss>

