Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
dodefb
Frequent Visitor

Rest API odata.count = 0

Hi Team,

i have a problem wtih the access token. 

I try get groups and access_token on learn.microsoft.com it's successfully and received 15 items

but when i try get token with C#, i can get but i try that token on postman i receiving "return @odata.count = 0" message.

 

Does anyone have any ideas?

 

Thank you

DoDe

 

postman.PNG

 


string tenantSpeceficAuthority = "https://login.microsoftonline.com/" + _tenantId + "/oauth2/v2.0/token";

var appConfidential = ConfidentialClientApplicationBuilder.Create(_clientID)
.WithClientSecret(_clientSecret)
.WithAuthority(tenantSpeceficAuthority)
.WithRedirectUri("http://localhost")
.Build();

string[] scopes = { "https://analysis.windows.net/powerbi/api/.default" };

var authResult = appConfidential.AcquireTokenForClient(scopes).ExecuteAsync().Result;
_accessToken = authResult.AccessToken;

5 REPLIES 5
dodefb
Frequent Visitor

Hi @v-yiruan-msft ,

i have solved my problems. We should have given permission each workspace to App Name.

but i have another problem. ı can get groups's users but can't report's users.

checked rest api doc it says use the "Admin - Reports GetReportUsersAsAdmin" method to get report users.

when it try this code i getting 401 unauthorized errror. 

Which permission i should add to my app?

 

dodefb_0-1716128968935.png

 

dodefb_1-1716129047130.png

 

Hi @dodefb ,

The 401 Unauthorized error usually occurs when the server is unable to authenticate the request. This could be due to incorrect credentials, insufficient permissions, or other issues related to authentication. Please review the following official documentation and check if you have gotten the proper permission.

Permissions

  • The user must have administrator rights (such as Office 365 Global Administrator or Power BI Service Administrator) or authenticate using a service principal.
  • Delegated permissions are supported.

When running under service prinicipal authentication, an app must not have any admin-consent required premissions for Power BI set on it in the Azure portal.


Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yiruan-msft 

thanks for reply, i had read that article on learn.microsoft.com but it's not clear for me.

as you know i using a service principal

What "When running under service prinicipal authentication, an app must not have any admin-consent required premissions for Power BI set on it in the Azure portal." means? what should i do?

v-yiruan-msft
Community Support
Community Support

Hi @dodefb ,

It seems like there might be an issue with the access token you are using. Could you please check the following info?

  • Make sure you have registered your application in Azure Active Directory and have the correct client ID and client secret.
  • Make sure you have the correct tenant ID for your organization.
  • Make sure you have the correct scopes for the Power BI API.
  • Make sure that _tenantId, _clientID, and _clientSecret are correctly set.
  • Make sure that the token has the necessary permissions to access the data you are trying to retrieve.
  • Access token is valid as access tokens are time-limited.

How do I get an OAuth 2.0 authentication token in C# - Stack Overflow

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

hi @v-yiruan-msft ,

i tried what you wrote but unfortunately i still taking same error (count=0)

i added all screenshots below, could you check its please.

 

Thank you

DD

 

dodefb_7-1715724176519.png

 

dodefb_2-1715723876586.png

 

dodefb_3-1715723920292.png

 

dodefb_4-1715723994444.png

 

dodefb_5-1715724008986.png

 

dodefb_6-1715724074599.png

 

 

 

dodefb_9-1715724452878.png

 

 

dodefb_8-1715724326925.png

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.