<?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: Power BI Rest API returns 401 authorized for some methods in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Rest-API-returns-401-authorized-for-some-methods/m-p/3380397#M43895</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/601725"&gt;@gddata&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;According to your provided info, it seems that you call REST API using service principal. But&amp;nbsp;&lt;SPAN&gt;service principal authentication is currently supported for the following &lt;FONT color="#FF0000"&gt;read-only&lt;/FONT&gt; admin APIs. You can find the details in the following official documentations.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal#considerations-and-limitations" target="_self"&gt;&lt;SPAN&gt;Considerations and limitations&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/enterprise/read-only-apis-service-principal-authentication" target="_self"&gt;&lt;SPAN&gt;Supported APIs&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vyiruanmsft_0-1692093156178.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/955538iF815347F2157C5D1/image-size/large?v=v2&amp;amp;px=999" role="button" title="vyiruanmsft_0-1692093156178.png" alt="vyiruanmsft_0-1692093156178.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
    <pubDate>Tue, 15 Aug 2023 09:52:49 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2023-08-15T09:52:49Z</dc:date>
    <item>
      <title>Power BI Rest API returns 401 authorized for some methods</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Rest-API-returns-401-authorized-for-some-methods/m-p/3375828#M43832</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I want to prepare a report that shows the usage statistics of our PowerBI reports. I wanted to use the PowerBI Rest API for this. I was able to access this API and do a few operations, but we cannot access other methods (Admin) that we want to access (such as creating a group, listing the group we created). We are getting a 401 error. I think that we have given the necessary authorizations on Azure and through Power BI Admin, but I think there is a point we missed.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PowerBI Portal Admin Settings" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/954220i6BB86ACF09CEBF05/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2023-08-11 at 10.31.22.png" alt="PowerBI Portal Admin Settings" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;PowerBI Portal Admin Settings&lt;/span&gt;&lt;/span&gt;&lt;BR /&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;RESOURCE_URL = 'https://analysis.windows.net/powerbi/api/.default' 
GROUP_URL = "https://api.powerbi.com/v1.0/myorg/groups"
ADMIN_URL = "https://api.powerbi.com/v1.0/myorg/admin/apps"
ADMIN_GROUP_URL_BASE = "https://api.powerbi.com/v1.0/myorg/admin/groups"
REPORT_URL = "https://api.powerbi.com/v1.0/myorg/groups/{}/reports"

token = { "bearer": None, "expiration": None }

headers = { "Content-Type': 'application/json" }
#response = requests.post("https://login.microsoftonline.com/", headers = headers, data = body)

auth = ClientSecretCredential (authority = AUTHORITY_URL, tenant_id = TENANT_ID, client_id = CLIENT_ID, client_secret = CLIENT_SECRET)
access_token = auth.get_token(RESOURCE_URL)
access_token = access_token.token
print(access_token)

bearer = access_token
token["bearer"] = "Bearer {}".format(bearer)
token["expiration"] = datetime.datetime.now() + datetime.timedelta(hours = 1)
rint(token)
headers = { "Authorization": token["bearer"] }

def CreateGroup(group_name:str):
    workspace_v2=True
    body = {
      "name": group_name
    }

    parameters = "?workspaceV2=True"
    
    response = requests.post(GROUP_URL + parameters, headers = headers, data = body)
    
    if response.status_code == HTTP_OK:
        print("New group created")

def GetGroups():
    response = requests.get(GROUP_URL, headers = headers)
    print(response)
    if response.status_code == HTTP_OK:
        print(response.json()["value"])

GetGroups()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Response :&lt;/P&gt;&lt;PRE&gt;&lt;A href="https://api.powerbi.com/v1.0/myorg/admin/groups?$top={$top}" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/admin/groups?$top={$top}&lt;/A&gt;
&amp;lt;Response [401]&amp;gt;&lt;/PRE&gt;&lt;P&gt;Please could you&amp;nbsp; suggest a way to solve this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 07:49:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Rest-API-returns-401-authorized-for-some-methods/m-p/3375828#M43832</guid>
      <dc:creator>gddata</dc:creator>
      <dc:date>2023-08-11T07:49:08Z</dc:date>
    </item>
    <item>
      <title>Re: Power BI Rest API returns 401 authorized for some methods</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Rest-API-returns-401-authorized-for-some-methods/m-p/3380397#M43895</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.fabric.microsoft.com/t5/user/viewprofilepage/user-id/601725"&gt;@gddata&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;According to your provided info, it seems that you call REST API using service principal. But&amp;nbsp;&lt;SPAN&gt;service principal authentication is currently supported for the following &lt;FONT color="#FF0000"&gt;read-only&lt;/FONT&gt; admin APIs. You can find the details in the following official documentations.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/developer/embedded/embed-service-principal#considerations-and-limitations" target="_self"&gt;&lt;SPAN&gt;Considerations and limitations&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/enterprise/read-only-apis-service-principal-authentication" target="_self"&gt;&lt;SPAN&gt;Supported APIs&lt;/SPAN&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vyiruanmsft_0-1692093156178.png" style="width: 999px;"&gt;&lt;img src="https://community.fabric.microsoft.com/t5/image/serverpage/image-id/955538iF815347F2157C5D1/image-size/large?v=v2&amp;amp;px=999" role="button" title="vyiruanmsft_0-1692093156178.png" alt="vyiruanmsft_0-1692093156178.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 09:52:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Power-BI-Rest-API-returns-401-authorized-for-some-methods/m-p/3380397#M43895</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-08-15T09:52:49Z</dc:date>
    </item>
  </channel>
</rss>

