migueesc123 / PowerBIRESTAPI

A Microsoft Power BI Data Connector or Power Query Connector for the Power BI REST API
MIT License
237 stars 74 forks source link

Admin - Datasets GetDatasourcesAsAdmin #23

Closed bsaragadam closed 4 years ago

bsaragadam commented 4 years ago

Admin - Datasets GetDatasourcesAsAdmin

While calling this API from the custom connector its failing to fetch the DatasourceID and gateway ID and shows as the error message.

image

image

I tried with online Power BI REST API try now

https://docs.microsoft.com/en-us/rest/api/power-bi/admin/datasets_getdatasourcesasadmin#code-try-0

Tried but its has 3 records and showing only 2 records.

{ "@odata.context": "http://wabi-west-us-redirect.analysis.windows.net/v1.0/myorg/admin/$metadata#datasources", "value": [ { "datasourceType": "Sql", "connectionDetails": { "server": "YYYYYYYYY", "database": "finance" }, "datasourceId": "4ce43ae2-2316-46ae-bd7e-94831d7e8003", "gatewayId": "5adf17b9-f7ae-40c0-902e-ac93f0a57c2c" }, { "datasourceType": "Sql", "connectionDetails": { "server": "YYYYYYYY", "database": "shared" }, "datasourceId": "162e83d0-035f-400f-b406-0556bd23b227", "gatewayId": "5adf17b9-f7ae-40c0-902e-ac93f0a57c2c" }, { "datasourceType": "Sql", "connectionDetails": { "server": "YYYYYY", "database": "finance" } } ] }

bsaragadam commented 4 years ago

@migueesc123 FYI.. I think its a bug from Microsoft.. I have opened the support ticket with them,

klinejordan commented 4 years ago

I contributed the Admin part of this connector, and to be honest, this call never really worked for me because my tenant (12,000+ datasets) is too big and the results never returned.

Keep me in the loop on what Microsoft says, i was only able to get this to work in a sandbox environment with only a few datasets and wouldn't be surprised if there's some datasets that don't return a datasourceID, in which case we have to update the Power Query behind this API call to account for JSON returns that don't include the expected columns.

klinejordan commented 4 years ago

@bsaragadam any update from Microsoft?

kazimrajani commented 4 years ago

Power BI Service Admin API and Functions are not working for me at all. It asks me to sign in and then errors out saying authentication error. I have the Power BI Administrator role assigned to my user account and still getting this error. I am unsure if its because of MFA enabled on my account due to a bug as described here.

image

Oddjobe commented 4 years ago

t asks me to sign in and then errors out saying authentication error. I have the Power BI Administrator role assigned to my user

Hi @kazimrajani ! Have you "Granted consent" in API Permissions (Azure AD/App registrations) ? image

kazimrajani commented 4 years ago

Hi @Oddjobe Thanks for the comment, I'll check with my infra team. Thanks kaz

oex-pbi commented 4 years ago

Power BI Service Admin API and Functions are not working for me at all. It asks me to sign in and then errors out saying authentication error. I have the Power BI Administrator role assigned to my user account and still getting this error. I am unsure if its because of MFA enabled on my account due to a bug as described here.

image

Similar to @kazimrajani - I cant get access to any Admin tables, even though Admin Consent has been granted in Azure

image

As you can see - admin has been granted, and other tables work OK

image

image

migueesc123 commented 4 years ago

Hey @oex-pbi !

This is a topic that I'm encountering with a lot of the connectors that I've created where the creation of the Web App and how it handles the OAuth 2.0 can be quite special.

Unfortunately, how the WebApp should be specifically set up for every case is something that is out of the scope of this project. The only aspect that we can control is the custom connector itself and how we make the calls and there's simply no other way to make the calls to those endpoints nor any way to bypass the authorization needed to see the resultset of those.

Here's also an screenshot from @klinejordan on how he has his WebApp setup and how it works for him: https://github.com/migueesc123/PowerBIRESTAPI/issues/19#issuecomment-561359108

but then again, it could be different for your AAD depending on how things are set up. If you ever discover a way to make this work for you, please post it here. My suggestion would be to start tracing your queries to the API and try to get deep into what's actually being revoked.

klinejordan commented 4 years ago

@oex-pbi When you go to the admin portal in the Power BI service, do you see the below options? Sometimes the role can be assigned but if your org is using Privileged Identity Manager you need to activate the role each time. If you don't see these options in the Admin Portal menu, your role isn't activated image

The real test for this is if you can make the admin API calls in Postman using the app registration client id/secret and your username/password then you will be able to use this custom connector. But if you're unable to make the calls in Postman then you won't. I've attached a postman collection with the sensitive information for my tenant removed but you should be able to use this to test. PBI Activity Logs.postman_collection.zip

oex-pbi commented 4 years ago

Many thanks @klinejordan the issue seems to be with MFA on the account. The account is Global Admin and Power BI Admin, so yes I see the Admin settings etc.

image

Any advice for handling MFA scenarios, as this cannot be disabled on this account

klinejordan commented 4 years ago

My account is MFA enabled and I have no issues calling the Admin APIs in both Postman and using this connector. Were you able to try to the Postman collection?

oex-pbi commented 4 years ago

Hi Jordan - Unfortuantely not, may just be my lack of experience with Postman I'm afraid - I'm only used to calling the APIs typically from ADF and Logic Apps - or from the 'Try it' feature on the PBI docs.

The example I normally use in Postman is as per below - method used is more straightforward - and i get this error:

image

There seems to be multiple requests in your example, it would be most helpful for you to advise where you would enter these details in Postman, such as a screenshot - I added the entire JSON to the raw section, updated the bearer token and entered crednetials, doesnt look like it wants to run

Or if you are available for 1:1 correspondance email me direct?

joeywas commented 4 years ago

Connect-PowerBiServiceAccount was working (about 7 days was when i was still using it) when authenticating with credentials that required MFA -- now results in errors:

Connect-PowerBIServiceAccount : Failed to get ADAL token: Unhandled Exception: System.AggregateException: One or more errors occurred. ---> Microsoft.IdentityModel.Clients.ActiveDirectory.AdalClaimChallengeException: AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access