0

I'm trying to call the powerbi api for a specific dataset, just to prove to myself that i have security set up correctly.

Ultimately, I will need to make a DAX query from code but to start, i'm using postman to make some basic request to ensure I've set things up correctly.

What Works

In the online app (app.powerbi.com), I can do the following (using my user credentials - aka I log in):

https://app.powerbi.com/groups/{groupid}/datasets/{datasetid}/details?experience=power-bi

This renders my table with all the columns / data.

What doesn't work

In postman, i'm trying to retrieve the data from the api like this:

https://api.powerbi.com/v1.0/myorg/groups/{groupid}/datasets/{datasetid}

But when I do, I get the following error:

{
    "error": {
        "code": "PowerBINotAuthorizedException",
        "pbi.error": {
            "code": "PowerBINotAuthorizedException",
            "parameters": {},
            "details": [],
            "exceptionCulprit": 1
        }
    }
}

I also tried to do a POST with a DAX query like this:

https://api.powerbi.com/v1.0/myorg/datasets/{datasetid}/executeQueries

with a body:

{  
  "queries": [  
    {  
      "query": "EVALUATE VALUES('Test Table')"
    }  
  ]  
}  

But I get the error:

{ "error": { "code": "PowerBIEntityNotFound", "pbi.error": { "code": "PowerBIEntityNotFound", "parameters": {}, "details": [], "exceptionCulprit": 1 } } }

Setup

I have created an application registration in azure called powerbi with the following permissions:

enter image description here

And then on the actual dataset, i have the following under "sharing" enter image description here

What I've tried so far

I've searched here on stack and found another post saying that I should decode the JWT token created for my app registration and make sure there's no roles embedded. I didn't see any field called role(s).

I also tried this request to the api: https://api.powerbi.com/v1.0/myorg/datasets/{datasetid}/refreshes

{
    "Message": "API is not accessible for application"
}

and the error I get there is:

Questions

In addition to the obvious question of why my calls to the API are failing, I'd like to doublecheck whether or not i need to include "myorg" in the Uris? Is it supposed to be a literal? or am i supposed to substitute it with another id? (like group id?).
According to MS's documentation, it seems to be a literal. Usually, for variables, they use the "{}" syntax to indicate.

What am I missing? Please and thanks.

5
  • Yes on including myorg. In Postman, are you sending any Authorization tokens? See Power BI REST API: What It Is & How to Use It + Examples - see steps 2 & 3.
    – Sam Nseir
    Commented Jan 23, 2024 at 16:41
  • @SamNseir yes, i'm generating and sending auth tokens using the app registration i created. We do this for other code, so i'm pretty sure the auth token we are using is correct. But happy to double check something / anything if you have specific suggestions
    – dot
    Commented Jan 23, 2024 at 16:47
  • @SamNseir is myorg supposed to be the literal string, or a variable representing my organization ID?
    – dot
    Commented Jan 23, 2024 at 18:27
  • myorg is literal.
    – Sam Nseir
    Commented Jan 24, 2024 at 4:00
  • The error might occur if you missed adding that app registration to your Power BI workspace with Admin/Contributor access. Check similar thread here stackoverflow.com/questions/77834978/…
    – Sridevi
    Commented Jan 24, 2024 at 4:25

1 Answer 1

1

The error occurs if you are using token generated with client credentials flow but missed enabling service principal to access your Power BI workspace.

I registered one Entra ID application and granted same API permissions as below:

enter image description here

In my Power BI workspace, I have dataset named SalesMarketing like this:

enter image description here

Now, I generated access token using client credentials flow via Postman with below parameters:

POST https://login.microsoftonline.com/tenantId/oauth2/v2.0/token
grant_type:client_credentials
client_id: appId
client_secret: secret 
scope: https://analysis.windows.net/powerbi/api/.default

Response:

enter image description here

When I used this token to make below calls, I too got same errors as you like this:

GET https://api.powerbi.com/v1.0/myorg/groups/{groupid}/datasets/{datasetid}/

Response:

enter image description here

GET https://api.powerbi.com/v1.0/myorg/datasets/{datasetid}/refreshes

Response:

enter image description here

To resolve the error, make sure to add your Entra ID app registration to Power BI workspace with Admin or Contributor access.

Go to Power BI Portal -> Your Workspace -> Click on ... -> Manage access -> +Add people or groups -> Search for Service Principal with name -> Admin

enter image description here

In addition to that, you have to allow access for service principals to call Power BI API by enabling below option in Admin Portal:

enter image description here

Now, generate the token again and call below API's where I got response successfully like this:

GET https://api.powerbi.com/v1.0/myorg/groups/{groupid}/datasets/{datasetid}/

Response:

enter image description here

Note that, service principal authentication is not supported for accessing My workspace (myorg).

In such cases, you need to either change your authentication method to delegated flow or use different API calls like this:

GET https://api.powerbi.com/v1.0/myorg/groups/{groupid}/datasets/{datasetid}/refreshes

Response:

enter image description here

You need to include myorg in all URIs and it is a literal that refers to My Workspace of your Power BI tenant.

Reference: PowerBI API error updating Dataset using Service Principal - Stack Overflow by Neil P and Andrey Nikolov

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.