<?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: Cannot get Power BI API POST call for &amp;quot;Datasets - Execute Queries In Group&amp;quot; to authori in Developer</title>
    <link>https://community.fabric.microsoft.com/t5/Developer/Cannot-get-Power-BI-API-POST-call-for-quot-Datasets-Execute/m-p/4407102#M59462</link>
    <description>&lt;P&gt;I resolved the issue myself. For anyone else running into this: the issue was the semantic model having row-level security enabled. It seems you cannot use service principals in this case.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is sparsely mentioned in the Power BI API endpoint limitations section, but would appreciate a clear API response from the API itself:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To use Service Principals, make sure the admin tenant setting&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/admin/service-admin-portal-developer#allow-service-principals-to-use-power-bi-apis" target="_blank" rel="noopener"&gt;&lt;EM&gt;Allow service principals to use Power BI APIs&lt;/EM&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;under&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;Developer settings&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is enabled. However, regardless of the admin tenant setting, Service Principals aren't supported for datasets with RLS per&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/admin/service-admin-rls#considerations-and-limitations" target="_blank" rel="noopener"&gt;RLS limitations&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;or datasets with SSO enabled.&lt;/P&gt;</description>
    <pubDate>Wed, 12 Feb 2025 14:05:25 GMT</pubDate>
    <dc:creator>CasperRademaker</dc:creator>
    <dc:date>2025-02-12T14:05:25Z</dc:date>
    <item>
      <title>Cannot get Power BI API POST call for "Datasets - Execute Queries In Group" to authorize</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Cannot-get-Power-BI-API-POST-call-for-quot-Datasets-Execute/m-p/4407074#M59460</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to call one of these two endpoints using Python, but running into 401 Unauthorized without any details from the API response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/execute-queries-in-group" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/execute-queries-in-group&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/execute-queries" target="_blank" rel="noopener"&gt;https://learn.microsoft.com/en-us/rest/api/power-bi/datasets/execute-queries&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is my code in Python, for full transparency versions used: Python 3.12.9, requests 2.32.2, msal 1.31.1&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;# internal imports
import configuration_details

# external imports
import json
import msal  # microsoft authentication library
import requests

(
    authority_url,
    azure_ad_client_id,
    azure_ad_client_secret,
) = configuration_details.retrieve_pbi_details()

authentication_context = msal.ConfidentialClientApplication(
    client_id=azure_ad_client_id,
    client_credential=azure_ad_client_secret,
    authority=authority_url,
    validate_authority=True,
)

token = authentication_context.acquire_token_for_client(
    scopes=["https://analysis.windows.net/powerbi/api/.default"]
)

access_token = token.get("access_token")

data = json.dumps({"queries": [{"query": "EVALUATE VALUES(Worklogs)"}]})

response = requests.post(
    data=data,
    url="https://api.powerbi.com/v1.0/myorg/groups/a365faf8-a136-48b7-96f0-2368934a9328/datasets/7284eead-fb8b-4fbf-9532-0c7df5dcd409/executeQueries",
    headers={
        "Authorization": f"Bearer {access_token}",
        "Content-Type": "application/json",
    },
    timeout=60
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The response is 401 with content `{'code': 'PowerBINotAuthorizedException', 'parameters': {}, 'details': [], 'exceptionCulprit': 1}`&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Checked:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;- Workspace ID and dataset ID are correct&lt;BR /&gt;- Service principal related to client ID had admin rights on the workspace&lt;/P&gt;&lt;P&gt;- Client secret is correct&lt;/P&gt;&lt;P&gt;- Other similar API calls work with the same code, for example GET&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;A href="https://api.powerbi.com/v1.0/myorg/groups/a365faf8-a136-48b7-96f0-2368934a9328/datasets/7284eead-fb8b-4fbf-9532-0c7df5dcd409" target="_blank" rel="noopener"&gt;https://api.powerbi.com/v1.0/myorg/groups/a365faf8-a136-48b7-96f0-2368934a9328/datasets/7284eead-fb8b-4fbf-9532-0c7df5dcd409&lt;/A&gt;&amp;nbsp;gives 200 response with dataset details.&lt;/DIV&gt;&lt;DIV&gt;- DAX query is correct, works in Power BI Desktop DAX query view and gives results&lt;BR /&gt;- In admin portal, "&lt;SPAN&gt;Semantic Model Execute Queries REST API" is "Enabled for the entire organization"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;- In admin portal, "Service principals can use Fabric APIs" is&amp;nbsp;&lt;SPAN&gt;"Enabled for the entire organization"&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Would appreciate any pointers on this. Thanks in advance!&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 12 Feb 2025 13:57:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Cannot-get-Power-BI-API-POST-call-for-quot-Datasets-Execute/m-p/4407074#M59460</guid>
      <dc:creator>CasperRademaker</dc:creator>
      <dc:date>2025-02-12T13:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get Power BI API POST call for "Datasets - Execute Queries In Group" to authori</title>
      <link>https://community.fabric.microsoft.com/t5/Developer/Cannot-get-Power-BI-API-POST-call-for-quot-Datasets-Execute/m-p/4407102#M59462</link>
      <description>&lt;P&gt;I resolved the issue myself. For anyone else running into this: the issue was the semantic model having row-level security enabled. It seems you cannot use service principals in this case.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It is sparsely mentioned in the Power BI API endpoint limitations section, but would appreciate a clear API response from the API itself:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To use Service Principals, make sure the admin tenant setting&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/admin/service-admin-portal-developer#allow-service-principals-to-use-power-bi-apis" target="_blank" rel="noopener"&gt;&lt;EM&gt;Allow service principals to use Power BI APIs&lt;/EM&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;under&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;Developer settings&lt;/EM&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is enabled. However, regardless of the admin tenant setting, Service Principals aren't supported for datasets with RLS per&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://learn.microsoft.com/en-us/power-bi/admin/service-admin-rls#considerations-and-limitations" target="_blank" rel="noopener"&gt;RLS limitations&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;or datasets with SSO enabled.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2025 14:05:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Developer/Cannot-get-Power-BI-API-POST-call-for-quot-Datasets-Execute/m-p/4407102#M59462</guid>
      <dc:creator>CasperRademaker</dc:creator>
      <dc:date>2025-02-12T14:05:25Z</dc:date>
    </item>
  </channel>
</rss>

