Forum Discussion
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
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;
Hi Anonymous ,
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?
6 Replies
- dodefbFrequent Visitor
Hi Anonymous ,
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?
- AnonymousNot applicable
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.
- 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
- dodefbFrequent Visitor
Hi Anonymous
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?
- AnonymousNot applicable
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.
- 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
- AnonymousNot applicable
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
- dodefbFrequent Visitor
hi Anonymous ,
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